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


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

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 <mfv49k11b7d@news3.newsguy.com> (permalink)
References <mfujm30hc5@news4.newsguy.com> <wwvegnx6pqh.fsf@l1AntVDjLrnP7Td3DQJ8ynzIq3lJMueXf87AxnpFoA.invalid>

Show all headers | View raw


On 2015-04-06, Richard Kettlewell <rjk@greenend.org.uk> wrote:

> Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:
>
>> 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
>
> There are two problems with your script.
>
> 1. There appears to be no #! line, meaning you have no control over
>    which shell runs it (and evidently your GUI and login shell are
>    making different decisions).
>
> 2. You are using == instead of = as the comparison operator.  The former
>    is a bashism.  It will not work in a non-Bash shell.
>
> With an explicit #! line mentioning /bin/bash, it becomes safe to use
> ==.  Without it, or with a #! line mentioning /bin/sh, you must restrict
> yourself to =.

Thanks for the pointers.  I tried adding a #!/bin/bash line and it worked.
It also works if I replace == with =.

What are the pros and cons of the two options?  The #!/bin/bash option
will not work on a system that doesn't have bash, or which has it somewhere
other than /bin.  This isn't a big thing because this script is only going
to be used on the one machine, but I like to develop portable habits.

By the same token, what about = vs. ==?  I've read that == is a bashism,
and that = is accepted as a synonym.  This sounds like the more portable
option, unless there are other considerations.

-- 
/~\  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 | Next 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