New to shell script and lost.... | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

New to shell script and lost....

UNIX for Dummies Questions & Answers


Tags
autosys

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-16-2008
LRoberts LRoberts is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 24 January 2012, 3:17 PM EST
Posts: 112
Thanks: 3
Thanked 0 Times in 0 Posts
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.

Last edited by LRoberts; 10-16-2008 at 12:47 PM..
Sponsored Links
    #2  
Old Unix and Linux 10-16-2008
kiranreddy1215 kiranreddy1215 is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 May 2009, 9:43 AM EDT
Location: SA
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 10-16-2008
LRoberts LRoberts is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 24 January 2012, 3:17 PM EST
Posts: 112
Thanks: 3
Thanked 0 Times in 0 Posts
Its bash.... I tried what you said but it does not seem to work :-(
    #4  
Old Unix and Linux 10-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 5 March 2015, 4:58 PM EST
Location: NM
Posts: 10,397
Thanks: 323
Thanked 850 Times in 789 Posts
$? is the return status of a process or command

Code:
#/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)

Sponsored Links
    #5  
Old Unix and Linux 10-16-2008
LRoberts LRoberts is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 24 January 2012, 3:17 PM EST
Posts: 112
Thanks: 3
Thanked 0 Times in 0 Posts
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...
Sponsored Links
    #6  
Old Unix and Linux 10-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 5 March 2015, 4:58 PM EST
Location: NM
Posts: 10,397
Thanks: 323
Thanked 850 Times in 789 Posts

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

&& is boolean "and" operator || is the "or" operator.
Sponsored Links
    #7  
Old Unix and Linux 10-16-2008
LRoberts LRoberts is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 24 January 2012, 3:17 PM EST
Posts: 112
Thanks: 3
Thanked 0 Times in 0 Posts
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'
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lost in shell script AdamSahp Homework & Coursework Questions 7 03-24-2012 07:06 PM
Data pipe lost when using ssh in shell script siavash Shell Programming and Scripting 2 02-01-2012 07:28 AM
My shell pipe 2 multipipes thread is lost ? jack2 Post Here to Contact Site Administrators and Moderators 6 03-19-2009 06:37 PM
Lost Data Lost Admin murphsr Filesystems, Disks and Memory 3 09-07-2005 03:35 PM



All times are GMT -4. The time now is 07:57 PM.