Subj : Re: Running a command dynamically in a script To : comp.os.linux From : steve_roach Date : Fri Jul 09 2004 09:35 pm Sybren Stuvel wrote in message news:... > steve enlightened us with: > > - 'ps' executes but does not redirect the output to a_file > > - Quite possibly because of this, when a_file can't be written to > > (maybe the > > target directory is owned by someone else), the status is 0 when it, > > in > > fact, failed. > > $ help eval > > Sybren Right on the money, Sybren. And just to prove it: ------------------------------------------------------------------------- [dev]$ ls -l total 24 -rwxr--r-- 1 steve dev 610 Jul 10 13:29 go -rw-r--r-- 1 steve dev 36 Jul 10 13:25 source -rw-r--r-- 1 steve dev 0 Jul 10 13:30 tmp.log [dev]$ cat source 1,ps > tmp.log 2,ps > /root/tmp.log [dev]$ cat go # Clear the log. rm -f tmp.log # Get a command that works call_text=`grep 1 source | cut -d',' -f2` # Show us the command echo "Command: $call_text" # Execute the command eval $call_text # See how it did status=$? # Did the redirect work? cat tmp.log # And tell us about it echo "This should be 0: $status" # Get a command that doesn't work call_text=`grep 2 source | cut -d',' -f2` # Show us the command echo "Command: $call_text" # Execute the command eval $call_text # See how it did status=$? # Did the redirect work? cat /root/tmp.log # And tell us about it echo "This should be 1: $status" [dev]$ ./go Command: ps > tmp.log PID TTY TIME CMD 19227 pts/0 00:00:00 bash 20869 pts/0 00:00:00 bash 20874 pts/0 00:00:00 ps This should be 0: 0 Command: ps > /root/tmp.log ../go: /root/tmp.log: Permission denied cat: /root/tmp.log: Permission denied This should be 1: 1 --------------------------------------------------------------------- BTW, good sig. .