Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 40
Verifying if the shell command executed or not?

Hi,

I am working on a shell script that would verify if the mount command has executed or not. So , i have been doing this.


mount /dev/cdrom /mnt/cdrom

echo "$?"

if [ "$?" = "0" ]; then

echo " Mount succesful"

else

echo " Mount unsuccessful"

fi


I have the problem with the if stmt. It is displaying " Mount successful even when it hasn't"


for example

echo "$?" would give 32, instead of going else loop, it still enters the if block of the code.


Can somebody help me with this.?


--Sundeep
Sponsored Links
  #2 (permalink)  
Old 05-12-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: H3X
Posts: 1,563

Code:

mount /dev/cdrom /mnt/cdrom

echo "$?"          # echo previous command exit code (mount)   .... remove this line!       

if [ "$?" = "0" ]; # if previous command exit code (echo) equal 0 ....

You get the point..
  #3 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 40
Thanks dude,


That was so stupid of me.

--Sunny
  #4 (permalink)  
Old 05-13-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
As a stylistic aside, that's really better written as


Code:

if mount /dev/cdrom /mnt/cdrom; then
  echo " Mount succesful"
else
  echo " Mount unsuccessful ($?)"
fi

Sponsored Links
Closed Thread

Bookmarks

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
Any way to know wt command has been executed from last 2-3 days ? manoja422002 UNIX for Advanced & Expert Users 3 03-26-2008 10:22 AM
perl - why is the shell script executed before the print command? mjays Shell Programming and Scripting 3 09-21-2007 06:49 AM
problem executed shell command from PL/SQL alodvg Shell Programming and Scripting 2 08-26-2006 03:58 AM
Verifying remote command status ravikiran HP-UX 0 06-08-2006 11:36 AM



All times are GMT -4. The time now is 03:48 PM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0