[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pausing a bash script
From: |
Paul Jarc |
Subject: |
Re: Pausing a bash script |
Date: |
Mon, 23 Feb 2009 12:49:28 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
DanSandbergUCONN <Daniel.Sandberg@uconn.edu> wrote:
> Hi All - If I want to write a script that uses ftp to transfer a file and
> then, only after the file has been successfully transferred, I do something
> else - how do I tell my script to wait until the ftp is finished before
> doing the next command? Is that even possible?
Waiting for the command to finish is what the shell normally does. If
a command is followed by "&", then you get the other behavior - the
command is started, and then the shell immediately continues with the
next command. Without "&", the shell waits for the command to finish
before proceeding.
To test that the command was successful, there are a few different
choices. You could use "set -e", as long as your script uses simple
enough syntax. But there are enough tricky situations that get in the
way of "set -e" that I never use it. You could put "&&" after every
command, to ensure that the script will stop at the first command that
fails. That's what I generally do. Or, if the ftp command is the
only one whose success you care about, you could use "if":
...
if ftp_command; then
echo the transfer was successful
else exit
fi
...
paul