Home | FAQ | Server | Presentations | Mailing Lists/Archives | Member Tools | Links | Sponsors | Contact
In bash you can check the last program's return code using the variable $?. In tcsh, you can use $status.
On most systems, you can use "echo -n whatever" to suppress newlines in echo.
ryan woodsmall
EMAIL:PROTECTED
________________________________
From: EMAIL:PROTECTED on behalf of Mike Miller
Sent: Thu 3/3/2005 3:56 PM
To: MLUG Members
Subject: Re: [MLUG] basic Unix pipe/exit code problem
On Thu, 3 Mar 2005, Jonathan King wrote:
> But as for your specific example:
>
>> ( /bin/false | gzip > /dev/null ) || echo fail
>
> Clearly shouldn't do what you want. You told gzip to take its standard
> input from a pipe, and even if a non-zero exit code is raised, I can't
> see how what you did should prevent gzip from sucking up it's stdin and
> compressing the result, which gives some trivial file of minimum length
But isn't he only trying to test the shell script to see if it responds to
the error code from 'false' even if 'false' is followed by more commands
in a pipe? The thing I don't understand is the mechanism by which the
shell gets the error code from 'false' - it isn't stdout or stderr.
> So check this out:
>
> jonathan% false | gzip> dorky.gz
So you can use gzip in pipes without using -c. That is good, and simple.
> Now, if you want my opinion, this (under tcsh) is much nastier:
>
> jonathan% echo "" | gzip > dorky3.gz
> jonathan% ls -l dorky3.gz
> -rw-r--r-- 1 jonathan staff 21 3 Mar 14:51 dorky3.gz
>
> Echo can never keep its mouth completely shut. Grr...
echo always sends a newline (\n), but isn't that true in any shell, not
just tcsh?
Mike
<<winmail.dat>>
_______________________________________________ members mailing list EMAIL:PROTECTED http://mlug.missouri.edu/mailman/listinfo/members