On Fri, 2005-08-05 at 08:01 +1000, James Gray wrote:
> On Thursday 04 August 2005 21:45, Matthew Hannigan wrote:
> > On Thu, Aug 04, 2005 at 04:18:21PM +1000, Ian Wienand wrote:
> > > e.g.
> > >
> > > #!/bin/bash
> > >
> > > output=">> /tmp/output"
> > >
> > > eval ls $output
> >
> > Just don't put the >> in the var.
> >
> > If you want it to go the screen, you can use /dev/tty.
> > Or for those unixes that support it, like linux, /dev/fd/1
> > is stdout.
>
> I thought /dev/stdout and /dev/stderr were the "POSIX-ly" correct forms?
> I've
> always used them in my scripts for this sort of thing and often move them
> from Linux <-> Solaris <-> BSD <-> AIX without needing much more than editing
> the #! line.
I've always just used the "tty" command to return the connected tty.
This seems to work consistently across many unices.
Eg.
if [ "${USE_SCREEN}" = "YES" ]
then
OUTPUT_STREAM=`tty`
else
OUTPUT_STREAM=/tmp/my_output_file
fi
echo "Hello" >> ${OUTPUT_STREAM} 2>&1
Checking the return code of "tty -s" can also be a good way to see if a
script has no connected tty, like the case where it has been called from
cron.
Cheers, Ben
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html