1

I have an executable bash file with commands.

It appears these files do not show what is being executed as the lines get executed by the terminal.

Is there a way to show the lines that are being executed?

Jsdodgers
  • 5,253
  • 2
  • 20
  • 36
  • @Dummy Code, you mean like write them twice ? one for execution and one for echo ? –  Aug 12 '13 at 02:21

2 Answers2

1

You would have to use bash's debugging option, bash -x HelloWorld.sh or #!/bin/bash -x

This will produce the following output...

+ echo 'Hello, World!'
Hello, World!

See more here

  • 1
    Try also the `-v` flag. I often find it more convenient than `-x`. You can combine them, but that's usually overkill. – tripleee Aug 12 '13 at 04:23
  • @tripleee I don't like that it prints everything rather than just the commands. –  Aug 12 '13 at 04:42
1

Another option is to add set -x to the script where you would like execution to begin debugging. You can also use set +x to stop.

Example:

#!/bin/sh
set -x
echo "This will be debugged"
set +x
echo "This will not be debugged"
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
David Maust
  • 8,080
  • 3
  • 32
  • 36