The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Ask Linux.com: Lost passwords, lost files, and terminal tricks redux iBot UNIX and Linux RSS News 0 08-31-2008 10:10 AM
invoking a shell script inside cgi shell script smriti_shridhar Shell Programming and Scripting 2 07-09-2008 02:50 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 09:42 PM
Lost Data Lost Admin murphsr Filesystems, Disks and Memory 3 09-07-2005 03:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-16-2008
LRoberts LRoberts is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 87
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..
  #2 (permalink)  
Old 10-16-2008
kiranreddy1215 kiranreddy1215 is offline
Registered User
  
 

Join Date: Nov 2007
Location: SA
Posts: 12
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
  #3 (permalink)  
Old 10-16-2008
LRoberts LRoberts is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 87
Its bash.... I tried what you said but it does not seem to work :-(
  #4 (permalink)  
Old 10-16-2008
LRoberts LRoberts is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 87
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...
  #5 (permalink)  
Old 10-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
$? 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)
  #6 (permalink)  
Old 10-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
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.
  #7 (permalink)  
Old 10-16-2008
LRoberts LRoberts is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 87
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?
Closed Thread

Bookmarks

Tags
autosys

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0