Skip to main content
edited tags
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
edited tags
Link
web
  • 193
  • 13
Source Link
web
  • 193
  • 13

Clean way to print command used to run script (stdin), stdout and stderr into file

I was attempting to run a script in bash: cc.sh

To run the bash script:

../cc.sh ../seq/ seqf

where ../seq/ and seqf are both arguments required.

I wanted to save the command I used to run the script (the command above), together with the output/result from the script into a log file.

I managed to print the output into a log file with tee command.

../cc.sh ../seq/ seqf 2<&1 | tee -a cc.log

cat cc.log:

"here is where the output shown"

While for the command itself, the closest I got is the script command. However, it seemed to save the command I used to run in a binary file.

Is there other better way to print the command other than script? Or better, print the command used to run the script file, together with the output/result into a log file?

Expected output for the log file:

COMMAND: ../cc.sh ../seq/ seqf
"here is where the output shown"