On Fri, May 30, 2008 at 10:36:30AM +1000, Amos Shapira wrote:
> Hi,
>
> I though I remember long time ago some trick that would allow a script
> to redirect its stdin/stdout from/to a file without having to enclose
> the entire script inside a sub-shell.
>
> I mean, something like:
>
> #!/bin/sh
>
> (command;
> command;
> ...
> ..) < /dev/null > output 2>&1
>
> Would work, but I think that I saw something to achieve the same in a
> more elegant way.
You probably mean 'exec'. From bash(1):
exec [-cl] [-a name] [command [arguments]]
If command is specified, it replaces the shell. No new process
[snip]
not be executed. If command is not specified, any redirections
take effect in the current shell, and the return status is 0.
If there is a redirection error, the return status is 1.
I.e.
exec < /dev/null > output 2>&1
>
> Does anyone know what I'm talking about?
>
> As a secondary question - for this specific script, it's important for
> me to actually close its standard input so when some of the commands
> get executed they'll know that they have nothing to wait on from the
> keyboard. Right now I just redirect it from /dev/null from the command
> line which executes the script but was wondering if there is a way to
> say "close fd 0" in shell inside the script itself.
No idea. I do not think that's possible. 'close' appears very few times
in bash(1).
>
> The environment is CentOS 5, but I like portable solutions.
I intended to not comment on this line of yours, then checked dash (a
Debian version of old 'ash'), and found out that it does have an
operator to close an fd:
In dash:
[n]<&- Close standard input (or n).
I do not see something like this (although there is very similar syntax
to duplicate an fd) in bash.
The 'exec' redirections are POSIX, as far as I know. I did not check
this.
--
Didi
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]