[NTLUG:Discuss] Bash related question

David Stanaway david at stanaway.net
Mon Feb 10 01:57:17 CST 2003


On Mon, 2003-02-10 at 01:33, Vaidya, Harshal (Cognizant) wrote:
> Hi,
> 
>   Consider this snippet of a bash script i am writing.
>   
> 1  retvalue = $(sftp2 -B ftpcommands db2admin at cq7092)
> 2  if [$retvalue -ne 0 ]
> 3   then
> 4  echo "file transfer failed"
> 5   else
> 6  echo "file transfer was successful"
> 7  fi
> 

$(*) is the same as `*`, that is, it is subsituted by the shell with the
standard output of the command enclosed.

The return value the last command executed by the shell is held in $?,
and the success or failure of a command can be used where a conditional
statment is used.

What you want is

if sftp2 -B ftpcommands db2admin at cq7092; then
  echo "file transfer was successful"
else
  echo "file transfer failed"
fi


Or if you wanted to be wierd

sftp2 -B ftpcommands db2admin at cq7092 && {
  echo "file transfer was successful"
} || {
  echo "file transfer failed"
}


-- 
David Stanaway <david at stanaway.net>



More information about the Discuss mailing list