I should have included this note - be careful with file descriptor 5. When
bash execs a child - it inherits fd 5.
E!
>
> Aha, that's the trick: the filedescriptor shuffle. And 2047 seems to
> be the largest file descriptor:
>
> (
> for i in 0 1 {3..10000} ; do
> line="exec $i> /dev/null $i>&-"
> eval "$line" || break
> done
> )
> -bash: 2048: Bad file descriptor
>
> which coincides with ulimit:
>
> $ ulimit -n
> 2048
>
> Thanks, Eric.
>
> Regards,
> - Robert
>
> On Wed, Dec 10, 2008 at 10:30 PM, Eric Wilson <[email protected]> wrote:
>>
>> 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"
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---