Execution Output of a shell script into a file.

Hi Experts,

I have a script called test.sh. I am trying to execute it with sh -x test.sh. Where i can find sequence of steps executed one by one. Now i want to these executions to be captured in a file.

i.e sh -x test.sh > output.txt

the above one is notworking.

can anyone help me regarding this.

Regards
Naree

Try this:

sh -x test.sh > output.txt 2>&1

use >& instead of >

Just to add that the above syntax is not standard:

$ sh -x test.sh >& output.txt
ksh: >&output.txt : illegal file descriptor name

It's supported by bash , zsh and (t)csh.

i used -x inside the shell script

kamaraj@kamaraj-laptop:~/Desktop/testing$ head sample.sh
#!/bin/sh -x
cat sample.txt | awk ' /./ {print $1}' | sort | uniq > output.txt

for i in `cat output.txt`;do 
    tot=0;
    num=`grep $i sample.txt|awk '{print$2}'`; 
        for j in $num;do 
            tot=`expr $j + $tot`;
        done;
    echo "$i --> $tot"; 
kamaraj@kamaraj-laptop:~/Desktop/testing$ ./sample.sh >& shell_output
kamaraj@kamaraj-laptop:~/Desktop/testing$ head shell_output 
+ cat sample.txt
+ awk  /./ {print $1}
+ sort
+ uniq
+ cat output.txt
+ tot=0
+ grep kamaraj sample.txt
+ awk {print$2}
+ num=34
35

I'm just saying that it's not standard.

It works with some shells.

Thanks experts. It really worked.