in bash shell
(my idea is redirect them to a tmp file first, and then read from it...)
works, but is stupid... any one could lend me a hand?
thx in advance
Mandrake C.
Mandrake C.
date_out=$(date) -or- date_out=`date` #note: "`" = backtick, not apostrophe
You might get a hold of a shell programming book, or do a google search
for "bash tutorial". bash is about 95% compatible with korn shell, so
a ksh book would be a reasonable substitute.
--
Dave Brown Austin, TX
1. Redirect output using a shell variable??
I am writing a ksh script in which I want to give the user the option to
see the output of the commands the script executes. I've never tried to
do this before (though I've written a fair number of ksh scripts), and
my first thought was to do something like this:
# show output by default
REDIR=
# if we saw the "hide output" command-line flag, hide it
if [ "$HIDE_OUTPUT" ]
then
REDIR=" > /dev/null 2>&1"
fi
# execute the command /path/foo
/path/foo $REDIR
However, ksh (and the Bourne shell, too) seems to execute /path/foo
(whatever it happens to be) using " > /dev/null 2>&1" as arguments to
the command rather than expanding the variable prior to execution.
For example, here's what I see in an interactive shell with ls:
$ temp=" > /dev/null 2>&1"
$ echo $temp
$ echo ls $temp
ls > /dev/null 2>&1
$ ls $temp
2>&1: No such file or directory
/dev/null
$
Can someone explain this behavior to me, and possibly suggest a solution
to my problem (I'd like to avoid the messiness of "if [ "$HIDE_OUTPUT" ]
then; /path/foo > /dev/null 2>&1; else /path/foo; fi" if at all
possible, since there are many places I want to use this)? Thanks for
any help...
Ernie Pistor
Sent via Deja.com http://www.deja.com/
Before you buy.
2. boot problem with unika notebook
3. need GDB help redirect command output to variable
4. Little "lockups" in 1.09. Any ideas?
5. please HELP with GDB output redirect to GDB variable !!!
6. SendMail - Restricting Users ...
7. capturing an output variable into a shell variable
8. How to increase MAXSYMLINKS?
9. Redirecting stderr output to a variable in PERL???
10. Using variables for redirecting output
11. Howto redirect the output of "time" into a variable?
12. bash function - can't redirect output to file
13. Can I redirect this output to a variable?