[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Brace expansions in if statement
From: |
John McKown |
Subject: |
Re: [Help-bash] Brace expansions in if statement |
Date: |
Thu, 29 Mar 2018 17:10:01 -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
> msger=echo
> break
> done
>
> msger="${msger:-notify-send}
>
> for same behaviour.
>
How about this?
msger=notify-send
printf "%s\n" tty{0..10} | fgrep -q "${GTTY}" && msger=echo
echo ${msger}
I do admit to liking the more "unusual" approach at times. I also don't
like interpreted loops.
>
> --
> Marco Arthur @ https://optdyn.com
>
>
--
I have a theory that it's impossible to prove anything, but I can't prove
it.
Maranatha! <><
John McKown