Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #14357

Re: Bash if statements fail under xfce launcher?

From Charlie Gibbs <cgibbs@kltpzyxm.invalid>
Newsgroups comp.os.linux.misc
Subject Re: Bash if statements fail under xfce launcher?
Date 2015-04-06 23:19 +0000
Organization NewsGuy - Unlimited Usenet $23.95
Message-ID <mfv49k01b7d@news3.newsguy.com> (permalink)
References <mfujm30hc5@news4.newsguy.com> <9t2bvbxj52.ln2@perseus.wenlock-data.co.uk>

Show all headers | View raw


On 2015-04-06, Dave Sines <dave.gma+news002@googlemail.com.invalid> wrote:

> Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
>
>> I've written a shell script that uses zenity to ask the user for
>> a parameter, so it can be run from an icon in Xfce rather than
>> the command line.  The if statements don't seem to be properly
>> evaluated when the script is run through the GUI, although the
>> script works properly when run from the command line.  Here's a
>> stripped-down example that illustrates the problem:
>> 
>> x=$(zenity --list --text="Select an option" --radiolist --height 250 \
>>   --column "" --column "Option" TRUE default FALSE test)
>> echo "zenity returned /$x/" >foo
>> if [ "$x" == "default" ]; then
>>     echo "Default option was selected" >>foo
>> elif [ "$x" == "test" ]; then
>>     echo "Test option was selected" >>foo
>> else
>>     echo "This should never happen!" >>foo
>> fi
>
>> Zenity is setting $x to the desired value, but the if and elif
>> statements don't recognize it.  Why should the if statements fail
>> when run from the GUI, when they work when run from the command line?
>> 
>> I'm running Debian Jessie - here's the output of uname -a:
>> 
>> Linux dragon 3.14-2-amd64 #1 SMP Debian 3.14.13-2 (2014-07-24) x86_64 GNU/Linux
>> 
>> The properties for my icon run the script from my home directory, which is
>> also specified as the working directory.  The "Use startup notification"
>> and "Run in terminal" checkboxes are not checked.
>> 
>> Are there any gotchas that I have to watch out for?
>
> It sounds as though the GUI is using sh (dash on Debian) when the script
> contains bash-specific extensions.
>
> Use single equals signs with the '[' command:
>
>   if [ "$x" = default ]; then
>   ...
>   if [ "$x" = test ]; then
>
> Or replace the entire if...fi block with a case statement:
>
>   case $x in
>    default) echo "Default option was selected" >>foo ;;
>    test)    echo "Test option was selected"    >>foo ;;
>    *)       echo "This should never happen!"   >>foo ;;
>   esac

Thanks for the tips.  That did the trick.

Beats the hell out of Microsoft support... :-)

-- 
/~\  cgibbs@kltpzyxm.invalid (Charlie Gibbs)
\ /  I'm really at ac.dekanfrus if you read it the right way.
 X   Top-posted messages will probably be ignored.  See RFC1855.
/ \  HTML will DEFINITELY be ignored.  Join the ASCII ribbon campaign!

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Bash if statements fail under xfce launcher? Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-04-06 18:35 +0000
  Re: Bash if statements fail under xfce launcher? Richard Kettlewell <rjk@greenend.org.uk> - 2015-04-06 20:06 +0100
    Re: Bash if statements fail under xfce launcher? Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-04-06 23:19 +0000
      Re: Bash if statements fail under xfce launcher? Richard Kettlewell <rjk@greenend.org.uk> - 2015-04-07 09:08 +0100
  Re: Bash if statements fail under xfce launcher? dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2015-04-06 20:20 +0100
    Re: Bash if statements fail under xfce launcher? Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-04-06 23:19 +0000

csiph-web