help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Brace expansions in if statement


From: Pierre Gaston
Subject: Re: [Help-bash] Brace expansions in if statement
Date: Thu, 29 Mar 2018 21:54:11 +0300

On Thu, Mar 29, 2018 at 9:12 PM, Felipe Salvador <address@hidden>
wrote:

> 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
> --
> Felipe Salvador
>
>
Well, you will not be able to make it work, you can only test one value at
a time and { } will create 10 different arguments for [.
in the end calling [ "$GTTY" = tty1 tty2 ....tty10]
I'd probably use a case statement like:

case $(tty) in
   *tty[0-9]|*tty10)  msger=echo;;
  *)  msger=notifysend ;;
esac


reply via email to

[Prev in Thread] Current Thread [Next in Thread]