[NTLUG:Discuss] Bash related question

Steve Baker sjbaker1 at airmail.net
Mon Feb 10 23:07:51 CST 2003


Vaidya, Harshal (Cognizant) wrote:

>   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
> 
>  When i run this script, the transfer actually completes successfully but i get an error at line 2 saying that 
>     " [: too many arguments"

A couple of people commented on that but...

> Moreover, the statement 6 is printed sometimes before the transfer starts and other times after the transfer  completes. Basically, it dosent run sequentially like a normal C program.

That's because there are TWO data streams involved - standard-out and standard-error.

The 'echo' command sends it's output to stdout - but the error messages went to stderr.

Because those two streams are not explicitly synchronized, it's possible for the order
of the outputs to get switched around.

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1 at airmail.net>    WorkEmail: <sjbaker at link.com>
HomePage : http://www.sjbaker.org
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
            http://tuxkart.sf.net http://prettypoly.sf.net




More information about the Discuss mailing list