# New to shell script and lost....

**URL:** <https://community.unix.com/t/new-to-shell-script-and-lost/216798>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [October 16, 2008, 11:41am UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798 "2008-10-16T11:41:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 11:41am UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/1 "2008-10-16T11:41:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kiranreddy1215](https://community.unix.com/letter_avatar/kiranreddy1215/32/5_5575768a8748004e209b776fc1b2916d.png) [@kiranreddy1215](https://community.unix.com/u/kiranreddy1215)\
**Post date:** [October 16, 2008, 11:55am UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/2 "2008-10-16T11:55:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 11:59am UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/3 "2008-10-16T11:59:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [October 16, 2008, 12:02pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/4 "2008-10-16T12:02:59Z")

</div>

$? is the return status of a process or command

```nohighlight
#/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)

```

---

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 12:03pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/5 "2008-10-16T12:03:20Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [October 16, 2008, 12:06pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/6 "2008-10-16T12:06:18Z")

</div>

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

```

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

---

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 12:09pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/7 "2008-10-16T12:09:17Z")

</div>

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'

---

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 12:12pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/8 "2008-10-16T12:12:08Z")

</div>

Opps forgot the other ] 😉

---

<div class="post-metadata">

**Author:** ![LRoberts](https://community.unix.com/letter_avatar/lroberts/32/5_5575768a8748004e209b776fc1b2916d.png) [@LRoberts](https://community.unix.com/u/LRoberts)\
**Post date:** [October 16, 2008, 12:18pm UTC](https://community.unix.com/t/new-to-shell-script-and-lost/216798/9 "2008-10-16T12:18:10Z")

</div>

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?
