Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want the actual command line be logged together with its output.

I routinely execute important commands like this:

PERL5LIB=${PERL5LIB}:/something/extra my-command.pl many arguments which I want to save 2>&1 | tee -a my-command.log

Now my-command.log contains both stdout and stderr of my-command.pl. However, it does not contain the actual command line above.

I know of the bash history file; so, I guess, I could copy from there (or from the terminal) by hand, but this is not a good solution, of course.

I guess I could write a shell function which would accept a command line, echo it, and then execute it, but then I would have to deal with the quoting hell.

I tried set -v but that appears to ignore redirection.

script does save the command line (but only if I have start a new shell, not with -c) but it does not work in the emacs shell interaction buffer and it saves the shell prompt too - including the escape sequences! - to its log file, so it is suboptimal.

share|improve this question
    
linux.die.net/man/1/script –  Zoredache Apr 24 '13 at 15:44
    
@Zoredache: script does not save the command line; for my purposes it is no better than tee -a. –  sds Apr 24 '13 at 15:48
    
script does save the command line AFAIK. Execute 'script' before you enter your command and it will record the entire session until you hit Ctrl+D. –  Jim G. Apr 24 '13 at 16:01
    
@JimG.: I just tried; it contains shell prompts and output from the commands I type, but not the commands themselves –  sds Apr 24 '13 at 16:07
    
@sds, that is very odd. It stores everything I type on my system, you must be doing something unusual. Try using screen, and enable log mode? –  Zoredache Apr 24 '13 at 16:20

1 Answer 1

up vote 2 down vote accepted

Try the -x option for bash:

bash -x "PERL5LIB=${PERL5LIB}:/something/extra my-command.pl many arguments which I want to save" 2>&1 | tee -a my-command.log

My test:

$ bash -x -c "echo a bunch of difffernt arguments"
+ echo a bunch of difffernt arguments
a bunch of difffernt arguments
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.