[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Brace expansions in if statement
From: |
Nick Chambers |
Subject: |
Re: [Help-bash] Brace expansions in if statement |
Date: |
Thu, 29 Mar 2018 16:16:11 -0500 |
On Thu, Mar 29, 2018 at 2:02 PM, Marco Silva <address@hidden> wrote:
> Excerpts from Felipe Salvador's message of 2018-03-29 20:12:21 +0200:
>> Hi list,
>> I'm trying to make bash to expand a brace expansion in a if statement.
>>
>> So, I've
>>
>> if [ "$GTTY" = tty{0..10} ]; then
>> msger=echo
>> else
>> msger=notify-send
>> fi
>>
>> where $GTTY is $(tty | cut -d'/' -f3).
>> It doesn't work.
>> I'm reading allot of web pages, but I cannot get over.
>> Could you please help me?
>>
>> Kind regards
>
> That won't work. tty{0..10} . You want a OR operation to all
> = tty{0..10}
>
> you can write:
>
> echo tty{0..10} | while read term; do
> if [ "$GTTY" == "$term" ]; then
if this is sh, you should be =, not == (== isn't POSIX). If it's bash, use [[
> msger=echo
> break
> done
>
> msger="${msger:-notify-send}
this is going to break due to http://mywiki.wooledge.org/BashFAQ/024
ubuntu:~ nchambers$ unset foo
ubuntu:~ nchambers$ printf 'here is some text\nand another\n' | while
read -r line; do
> foo=$line
> done
ubuntu:~ nchambers$ declare -p foo
-bash: declare: foo: not found
ubuntu:~ nchambers$
>
> for same behaviour.
>
> --
> Marco Arthur @ https://optdyn.com
>