Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
#!/bin/bash
# auto-cd: script for lazy people
#
eject
sleep 5
eject -t
mount /cdrom # you might have to change this if you don't use SuSE
#Here comes the funny part
if ( `echo $?` -eq 0)
then
konqueror /cdrom #change this to nautilus if you use gnome
else
exit 1
fi#Now just create a link on your desktop
#to this file and you'll be 1 click away from the contents of your cd##NOTE: if you execute it, you'll get a auto-cd: 0: command not found
## My question is, why the function does not work?
## The `echo $?` should test if the mount command was successful. If it
## was successful, then it should open your file browser and display the contents
## of the cd, if mount was unsuccesful, then it should exit without calling konqueror
## or nautilus.

>> if ( `echo $?` -eq 0)
ahemm...
sure both of you do not want to use square brackets? ;-)all these are possible:
if [ `echo $?` -eq 0 ] ...
if [ $? -eq 0 ] ...
if [ `echo $?` == 0 ] ...
if [ $? == 0 ] ...as == and -eq are the same, and the contents of an environment or special variable is certainly equal to its output via echo.. but the [] brackets, or more specifically, the '[' (begin boolean evaluation) shell builtin and the corresponding ']' end-of-evaluation marker, are necessary because elsewhere the -eq and == operators are not valid.
in fact, [ is a perfectly normal shell builtin, you could also write this:
[ $? == 0 ] && konqueror /cdrom || exit 1
which boils down the if block to one line.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |