Operating System - HP-UX
1820636 Members
1980 Online
109626 Solutions
New Discussion юеВ

If sentence .... (using or parameter)

 
SOLVED
Go to solution
Manuales
Super Advisor

If sentence .... (using or parameter)

is correct the following sentence with if command?

if [[ $6 != "a.sh" ]] || [[ $6 != "b.sh" ]]
then
echo "Im in the function..."
fi

$6 = hola
why enter program if $6 is hola and not b.sh or a.sh?

Thanks.

2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: If sentence .... (using or parameter)

First, never test a variable that might be null test "${6}" rather than ${6}

Second, your syntax is bad.

if [[ "${6}" != "a.sh" || "${6}" != "b.sh" ]]
then
...
fi

OR
if [ "${6}" != "a.sh" -o "${6}" != "b.sh" ]
then
...
fi

finally you have a logical error

${6} is always going to not equal one of your constants so the statement will always be true. You probably meant AND rather than OR so substitute "&&" for "||" or "-o" for "-a".

The [[ ]] style if statement is more efficient because it is evaluated directly by the shell (Korn or POSIX) whereas the more traditional [ ] style is evaluated by the external test command.
If it ain't broke, I can fix that.
Manuales
Super Advisor

Re: If sentence .... (using or parameter)

THANKS A LOT !!!

Manuales :=)