How to write this script?
Paul Howarth
paul at city-fan.org
Tue Apr 12 14:26:56 UTC 2005
Hongwei Li wrote:
> I have a basic question about a script. In this script, I want to mount a
> network drive, if successful, then do somethings, otherwise, exit. My
> script is like this:
>
> #!/bin/csh
> if ( `mount sever2:/opt /mnt` ) then
> ....
> umount /mnt
> endif
>
> When I run this script, it does mount the network drive (server2 has done
> all nfs, exportfs etc.), but did not do anything inside the if-endif, and
> did not umount it. How should I write this script?
In your script, the `mount sever2:/opt /mnt` runs the command and any
output generated by the command is substituted into where the quote
marks were. So, if as normal, no output is produced, you end up with:
if ( ) then
...
endif
which doesn't make much sense. You don't need the backquotes.
I'd steer clear of scripting in csh if I was you
(http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/). In sh you could
do it like this:
#!/bin/sh
if mount sever2:/opt /mnt; then
...
umount /mnt
fi
Paul.
More information about the fedora-list
mailing list