I am porting an old ksh script to Bourne shell. The old ksh script contains the following code:
#!/bin/sh tmpLog=/var/tmp/logfile.$$ exec 1> $tmpLog exec 2>&1 eval $* another_command_1 another_command_2
From what I read, it seems that these two exec statements are intended to execute $*, another_command_1, another_command_2 and all following commands; and then redirect all STDERR and STDOUT from those commands into
/var/tmp/logfile.$$. However, when I run this in a script the script fails after
stefanl@host:~ $ sh -xv ./output.sh echo "Hello" #!/bin/sh tmpLog=/var/tmp/logfile.$$ + tmpLog=/var/tmp/logfile.39918 exec 1> $tmpLog + exec exec 2>&1 + exec stefanl@host:~ $
And when I run this on the commandline, my shell freezes after I execute
stefanl@host:~ $ tmpLog=/var/tmp/logfile.$$ stefanl@host:~ $ exec 1> $tmpLog stefanl@host:~ $ exec 2>&1 ### FREEZE ###
- What is
exec 2>&1supposed to do?
- Why is it failing for me?