permissions issue on print to a file

Brian K. White brian at aljex.com
Mon Dec 4 12:30:56 PST 2006


----- Original Message ----- 
From: "Nancy Palmquist" <nlp at vss3.com>
To: "Dennis Malen" <dmalen at malen.com>; "filePro List" 
<filepro-list at lists.celestial.com>
Sent: Monday, December 04, 2006 2:36 PM
Subject: Re: permissions issue on print to a file


> Dennis Malen wrote:
>> Nancy,
>>
>> I assume fm is the name of the file. What is the rest after fm:
>>
>> fm{" 2>&1"

that should really be
fm<"2>&1"

The { would suck the 2 right up against the filename making it part of the 
filename in fm.
I guess including a space in the litteral after the { must have been saving 
it all those times but it's safer to do it right.

2>&1 means to take stderr (2) and redirect it (>) to stdout (&1)

you place this after you do something with stdout, though that seems 
counterintuitive

earlier in the command she had  ">"{fm

Just putting ">" after a comand is the same as saying "1>"  which is to say, 
take stdout (1) and redirect it (>) to the file fm

So the full command reads:
run program, capture it's stdout to file fm, capture it's stderr to stdout
which means both stdout and stderr will go into file fm instead of the 
screen

I often capture them to two different files or direct only one to /dev/null 
and capture the other to file.

program >file.out 2>file.err
[ -s file.err ] && { echo "there was an error!" ; cat file.err ; exit 1 ; }
[ -s file.out ] || { echo "program produced no output" ; exit ; }
# if we get here we can just use file.out normally
# there was no error and file.out is not empty

or sometimes you know it's normal the command will/may fail sometimes and 
don't care, you just want the output, or lack of output, and ignore any 
errors:

ls *.csv >list.txt 2>/dev/null

list.txt in this case will always only have filenames, or nothing. Very easy 
to deal with that.
When there are no files, ls generates an error message, but it generates it 
on stderr which we've directed to /dev/null

Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro  BBx    Linux  SCO  FreeBSD    #callahans  Satriani  Filk!



More information about the Filepro-list mailing list