4

The script command executes and records logs.

( http://www.computerhope.com/unix/uscript.htm )

( http://linuxers.org/article/script-command-line-tool-recordsave-your-terminal-activity )

I use script command for saving commands and those output.

Whenever using 'script', I type commands like followings.

$ script result.log
Script started, file is result.log
$ date
$ ls -la.
$ exit

Sometimes I want to use those command with shell script.

So I run like following.

$ script -c test.sh result.log

But the result.log has only output, it doesn't contain command itself. I want the result.log to include commands and output.

How can I do it?

Thanks

1
  • All these years I didn't know about this command. Nice one, thanks! Commented Dec 23, 2014 at 8:50

2 Answers 2

3

if you use sh -x to run your script it will print the commands or add set -x to your script.

script -c "sh -x ./test.sh" reult.log

sample output:

+ date
Tue Dec 23 09:52:22 CET 2014
+ ls -la
Sign up to request clarification or add additional context in comments.

Comments

0
 set -o verbose

Execute this on terminal before executing your script or add this at the beginning of the script.

This will change the terminal configuration to echo all the commands before executing them.

This will add the command then followed by the output of that command.

you can also use :

 set -x or set -v set -xv

-x option enables variable expansion and echo's all the option used with the command.

-v is similar to -o verbose this simply echo's the command name

-xv echo's both.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.