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

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

Thanks dude,

That was so stupid of me.

--Sunny

As a stylistic aside, that's really better written as

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