I have a bash script sometimes called by another script and sometimes run 
from the command line.  I would like standard output (and error) to go to 
the screen if I run the script from the keyboard and to a nominated file 
if I call it from another script.

I tried the following


if [ "$1" = "quiet" ]; then
     R=">> /home/steven/mfgbacker/serr 2>&1"
else
      R=""
fi

[...snip...]

DTEN=`date "+%Y.%m.%d %H:%M:%S"`
echo "inside makedvd $DTEN" $R

I=`mkisofs -R -J -q -print-size /back1/tarback/*.tgz`
J="tsize=${I}s"
mkisofs -R -J -q -o /back1/tarback/dvd.iso /back1/tarback/*.tgz $R
cdrecord -sao $J dev=ATAPI:0,0,0 speed=2 driveropts=burnfree 
/back1/tarback/dvd.iso $R  

[...snip...]

The $J substitution into the last command works fine but the $R bit, which 
attempts to redirect the output to a file, does not.  Bash seems to 
interpret the >> bit as part of the command rather than a redirection 
instruction.

I am not sure if this is possible in bash or not.  There are lots of other 
commands in the script which also redirect so I would rather not do 
something like:

if ["$1" = "quiet"]; then
   mkisofs -R -J -q -o /back1/tarback/dvd.iso /back1/tarback/*.tgz >> 
/home/steven/mfgbacker/serr 2>>1
else
   mkisofs -R -J -q -o /back1/tarback/dvd.iso /back1/tarback/*.tgz
fi

because I would have to do it many times.

I think the problem is something to do with when bash is processing the 
substitution.  I have tried various combinations of different quotes 
without success.

Could someone please point me in the right direction

Thank you and regards
Steven


-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to