2

I want to set all debugging output to a log file. So I checked command line - bash: set -x logs to file | Ask Ubuntu and followed the instructions.

test-script:

#!/bin/bash exec 5 >/var/log/test.log export BASH_XTRACEFD=5 main(){ set -x echo hello set +x } main 

run:

./test-script 

returns:

exec: 5: not found 

The manual shows you can do this as well, so why is the above not working?

0

    2 Answers 2

    5

    There should be no space between 5 and > on the exec line.

    With the space, the script tries to execute a command called 5, which is why you get "not found".

    Without the space, you attach file descriptor 5 to the given file name for output.

    Additionally, there is no need to export the variable BASH_XTRACEFD, it's enough to just set it:

    #!/bin/bash exec 5>test.log BASH_XTRACEFD=5 main () { set -x echo hello set +x } main 
      3

      The error gets you halfway there:

      exec: 5: not found

      exec tried to execute a command called 5, and didn't find it.

      The syntax for redirecting a file descriptor calls for no space between the file descriptor number and the redirection operator, like so:

      exec 5> /var/log/test.log 

        You must log in to answer this question.

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.