Re: How to write this script?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux