How about reassigning stdout with other file descriptors, then reassigning it
back.

--
#!/bin/bash
exec 7>&1            # redirect stdout
exec > $2            # output to file

echo "hello"

exec 1>&7 7>&-       # Restore stdout

echo "world"

---


Cheers;

E!



>
> Yes: so that I can have change the default destination of stdout and
> stderr without having to explicitly state the redirect for each
> command.
>
> Here's a slightly different example:
>
> $ ( exec > log 2> log.err ; echo hello ; date ; foo )
> $ tail -v -n 1 *
> ==> log <==
> Wed Dec 10 21:42:15 CST 2008
>
> ==> log.err <==
> bash: foo: command not found
>
> Also, /dev/console doesn't work:
>
> $ ( echo "world" > /dev/console)
> bash: /dev/console: Permission denied
>
> Regards,
> - Robert
>
>
> On Wed, Dec 10, 2008 at 8:52 PM, Eric Wilson <[EMAIL PROTECTED]> wrote:
>>
>> Any reason to not explicitly redirect stdout stream (man 3), rather than the
>> /dev/stdout device? or am I not understanding the problem?
>>
>>
>> ( echo "hello" > afoo; echo "there" > bfoo; echo "world" > /dev/console)
>>
>>
>> Cheers;
>>
>> E!
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
Central West End Linux Users Group (via Google Groups)
Main page: http://www.cwelug.org
To post: [email protected]
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
More options: http://groups.google.com/group/cwelug
-~----------~----~----~----~------~----~------~--~---

Reply via email to