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.
Does anyone know what I'm talking about?
If you run "exec" without giving it a parameter, it will not execute
anything, but the redirection will take effect.
"exec < /dev/null >output 2>&1" will do what you want.
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.
AFAIK there is no such way, but as far as I know, redirecting to
/dev/null is the official way to do what you want. Very few program can
actually work with stdin/out actually not valid file descriptors. Even
when running daemons, the programming guidelines say "close them all and
open /dev/null".
Shachar
=================================================================
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]