TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:1502] odd bash script problem
Same problem as in batch file string compares under dos when 1 string
was empty.
Since $2 doesnot exist when you donot specify "new" the if commands sees
the expression '= "new"'. In a test the first token can be a variable or an
unary
operatory (e.g. not ! ). In this case it sees a "=" sign and throws up.
Replace the if condition with
if [ "x$2" = "xnew" ]
and if $2 is null the the LHS evaluates to "x" which is not null and you will
be fine.
Here is the complete thing. Donot forget the space between the "if" and the
"["
The "[" is nothing but an alias to the "test" command. So if there is no space
then the shell sees "if[" as a command and cannot find it.
---
if [ "x$2" = "xnew" ];
then
netscape -remote "openURL( $1, new-window)"&
else
netscape -remote "openURL( $1 )"
fi
---
sandipan
In a message dated 9/30/98, 7:41:17 AM, tclug-list@listserv.real-time.com
writes:
<<if [ $2 = "new" ]
then
netscape -remote "openURL ($1, new-window)"&
fi
netscape -remote "openURL ($1)"&
It works except when I don't have new as $2, I get the following message
[lueyb@pcLueyB /]$ newnetscape http://www.linuxnow.com
/usr/local/bin/newnetscape: [: =: unary operator expected >>