How to write this script?
Hongwei Li
hongwei at wustl.edu
Tue Apr 12 14:34:27 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.
>
Thank yo very much! It is working now.
Hongwei
More information about the users
mailing list