1

I want to source a file containing several commands in a bash shell. How can I have the currently executed command printed on top of the commands output?

E.g. given this file test.sh

echo "hello"
echo "world"

the output of source test.sh should be:

echo "hello"
hello
echo "world"
world
Alexander Presber
  • 6,429
  • 2
  • 37
  • 66

1 Answers1

1

Type set -x before source test.sh. This tells the shell to show the commands that are being executed before executing them.

Type set +x to undo it afterwards.

Barmar
  • 741,623
  • 53
  • 500
  • 612