In QNX4 I used to be able to say in a shell script:
if [ -n $XYZ -a $XYZ == XYZ ]; then
in QNX6 I seem to have to change this to:
if [ -n $XYZ ]; then
if [ $XYZ == XYZ ]; then
I understand why it is failing when the $XYZ expression is NULL, but
why in QNX6 is the shell parsing the second expression if the first
expression is FALSE?
Also, (completely different issue), why do
if [ -n $XYZ ]
and
if [ -z $XYZ ]
both return TRUE if $XYZ is undefined?
And is there a way to test IF XYZ is defined?
(I saw that I can assing a different value to a variable based on weather
or not XYZ is defined.)
In QNX4 I used to be able to say in a shell script:
if [ -n $XYZ -a $XYZ == XYZ ]; then
in QNX6 I seem to have to change this to:
if [ -n $XYZ ]; then
if [ $XYZ == XYZ ]; then
I understand why it is failing when the $XYZ expression is NULL, but
why in QNX6 is the shell parsing the second expression if the first
expression is FALSE?
Also, (completely different issue), why do
if [ -n $XYZ ]
and
if [ -z $XYZ ]
both return TRUE if $XYZ is undefined?
And is there a way to test IF XYZ is defined?
(I saw that I can assing a different value to a variable based on weather
or not XYZ is defined.)
liug <liug@mama.indstate.edu> wrote:
: quote your shell variable so it looks like
: if [ -n “$XYZ” -a “$XYZ” == XYZ ]
The other trick folks are using is this
if [ z$XYZ == zXYZ ]
The problem is that the expansion is done before by the shell
so this:
if [ -n $XYZ -a $XYZ == XYZ ]; then
will end up looking like this:
if [ -n -a == XYZ ]; then
if the variable $XYZ is not set, definitely not what you want
and undefined behaviour depending on the command test i.e. [
: Bill Caroselli <qtps@earthlink.net> wrote:
:> In QNX4 I used to be able to say in a shell script:
:> if [ -n $XYZ -a $XYZ == XYZ ]; then
:> in QNX6 I seem to have to change this to:
:> if [ -n $XYZ ]; then
:> if [ $XYZ == XYZ ]; then
:> I understand why it is failing when the $XYZ expression is NULL, but
:> why in QNX6 is the shell parsing the second expression if the first
:> expression is FALSE?
:> Also, (completely different issue), why do
:> if [ -n $XYZ ]
:> and
:> if [ -z $XYZ ]
:> both return TRUE if $XYZ is undefined?
:> And is there a way to test IF XYZ is defined?
:> (I saw that I can assing a different value to a variable based on weather
:> or not XYZ is defined.)
liug <> liug@mama.indstate.edu> > wrote:
: quote your shell variable so it looks like
: if [ -n “$XYZ” -a “$XYZ” == XYZ ]
The other trick folks are using is this
if [ z$XYZ == zXYZ ]
Or, even safer, do both:
if [ “z$XYZ” == zXYZ ]
The quotes protect you from $XYZ being empty or containing a space, but
often you still need to do something about the case of $XYZ starting
with a dash.
BTW A single “=” is equivalent to “==” but more portable: the “=” is
POSIX, while the “==” is not.
Alain Magloire <> alain@qnx.com> > wrote:
liug <> liug@mama.indstate.edu> > wrote:
: quote your shell variable so it looks like
: if [ -n “$XYZ” -a “$XYZ” == XYZ ]
The other trick folks are using is this
if [ z$XYZ == zXYZ ]
Or, even safer, do both:
if [ “z$XYZ” == zXYZ ]
The quotes protect you from $XYZ being empty or containing a space, but
often you still need to do something about the case of $XYZ starting
with a dash.
BTW A single “=” is equivalent to “==” but more portable: the “=” is
POSIX, while the “==” is not.
Thank you Alain & Wojtek.
I did understand why it wasn’t working. I didn’t understand why it did work in QNX4.
I did not know about the ‘==’ thing. Thanks.
My old scripts were written using the QNX4 helpviewer pages.
I see that this documentation has been updated for QNX6.
Thanks Steve.
David Kuechenmeister <> david.kuechenmeister@viasat.com> > wrote:
Thanks for the tips about strings. Now how about numbers? I can’t seem
to
test for the correct number of command line arguments.
if [ $# -ne 1]
then
…
fi
The shell is fussy about parsing tokens. Try a space before the ‘]’.
if [ $# -ne 1 ]