[ale] Bash script
Mark J. Reed
mark_reed at sware.com
Tue Apr 2 07:23:05 EST 1996
Sure, easy. If CDROM is null, then
[ -n $CDROM ]
expands to just
[ -n ]
since the "-n" test flag requires an argument, bash complains. To
solve this, put the $CDROM inside double quotes. Then
[ -n "$CDROM" ]
expands to
[ -n "" ]
and the shell is happy. As a general rule, any time you're expanding a
shell variable, put double-quotes around the expansion, unless you
explicitly want its value to be split up by whitespace and neither you
nor the shell cares if it's null.
David Hamm writes:
\ I am developing a genuine hate for the bash parser
\ the following shell script creats the output listed below it. The
\ script works but it emits an error. Can anyone tell me where I'm going
\ wrong?
\ ********** the shell script
\ #!/bin/sh
\ CDROM=`grep cdrom /etc/mtab`
\ if [ -n $CDROM ]; then
\ echo Mounting Cdrom under /cdrom
\ mount -r -t iso9660 /dev/cdrom /cdrom
\
\ else
\ echo Unmounting Cdrom mounted under /cdrom
\ umount /cdrom
\ sleep 1
\ eject
\ fi
\
\ ******** the output **********
\ /usr/bin/cdrom: [: too many arguments
\ Unmounting Cdrom mounted under /cdrom
--
Mark J. Reed
Email: mark_reed at sware.com - Voice: +1 404 315 6296 x158 - Fax: +1 404 315 6407
Hewlett-Packard Co. / 2957 Clairmont Rd Suite 220 / Atlanta GA 30329-1647
E-Mail Privacy by SecureMail. Visit URL:http://www.secureware.com/ for details.
More information about the Ale
mailing list