New to shell script and lost....

I am really stuck on something I am sure you all will find simple.
I am VERY new to shell scripting and I am trying to figure out how to do a or statement below. So if it = 11 or 31 then...

if [ $? != '11' ]; then

Please keep in mind I do not know much on shell scripting and thank you in advance as I learn.

hi ,
please note the syntax changes per shell , you have not mentioned the shell
i will tell how to do it in ksh

if [ "$x" = "11" ];then
if [ "$x" = "31" ] ;then
<<do something >>> -- atleast 1 statement
else
<< if you want some-thing in else -case >>
fi
fi -- if u want any else case then u can put a else as a layer

Its bash.... I tried what you said but it does not seem to work :frowning:

$? is the return status of a process or command

#/bin/ksh
some_command goes here
it=$?
# one way
if [[ $it -eq 31 || $it -eq 11 ]] ; then
# do something
fi
# or this way, preserving the result of the test for further use
test_result=$(( it == 11 | it == 31 ))   #  C boolean operators:  ==, !=, >, >=, etc.
# at this point test_result is either 0 (not true) or 1 (true)

I tried it this way thinking it would work....

if [ $? != '11' ] || [ $? != '31' ]; then

But that did not seem to work. I need to check if the $? is either a 11 or a 31. If its not either one then do action.

I am really lost on the format...

#!/bin/bash
if [ <comparison 1>  ||  <comparison 2> ] ; then
   # do stuff here if either comparison succeeds
fi

&& is boolean "and" operator || is the "or" operator.

I tried the above way....
it=$?
if [[ $it -eq 11 || $it -eq 31 ] ; then

But I am getting this...

line 23: syntax error in conditional expression
./CheckAutoUpTest: line 23: syntax error near unexpected token `]'
./CheckAutoUpTest: line 23: `if [[ $it -eq 11 || $it -eq 31 ] ; then'

Opps forgot the other ] :wink:

Ok I got this now....

Value=$?
if [[ $Value != '11' || $Value != '31' ]]; then
echo $Value
echo "Code 11: CheckAutoUp is reporting Autosys as down. Sending event to Omnibus..."
$EIF_HOME/bin/solaris2/postemsg -f$EIF_HOME/eif.conf -rFATAL -m"AutosysCheckAutoUp has failed." OnCallGroup="INFR_APPS" ISOC_Instruc
tions="Please contact INFR_APPS." TEC_Class=68403 AUTOSYS_CHKAUTOUP Autosys

I know the value does = 11. For some reason the above code is doing the then statement even though the value does = 11.

What am I doing wrong?