0

I'm not sure I address this problem correctly, but I've search and search over the net and found nothing, yet.

I'm writing a bash script and I want to see what the script is really doing when being executed, like a log of all the commands, one by one, what are executed - this way, I'll be able to see why my script is falling.

Note : I've post similar question in the past, someone told me I run my bash script with sh -xe script.sh but it doesn't give me enough information to debug properly.

Please advise. Thanks!

7
  • Would it make sense to write some information to the syslog, as part of your script? Commented Jul 10, 2020 at 19:15
  • @noam: As far as I understand,no. I do not want to write the log myself, with logger, I want to see what are all the commands that my script is running. In fact,I got a curl with a variable in it, and it always giving me an error. For testing purpose, I'm able to run it by writing the content of the variable manually, and it works, but I need it with a variable.And I've many other curl with variables, they all works fine, but a specific one always give me an error and it makes no sense. So I'm trying to see what is the final command exactly, that the bash terminal is receiving from my script Commented Jul 10, 2020 at 19:28
  • Where do you want to see the results? You can add some debug prints, which is the same as logging messages, except that they will be printed to STDOUT. Commented Jul 10, 2020 at 19:37
  • How to create a Minimal, Reproducible Example Commented Jul 10, 2020 at 19:40
  • 1
    Putting set -x in your script is exactly the same thing as running bash -x yourscript, which is what you're saying someone already told you to do (except that they were suggesting set -e as well, which is generally a bad idea, and suggesting use of sh, which is not bash). Commented Jul 10, 2020 at 20:13

1 Answer 1

1

Adding set -x at the beginning of the script displays, in the terminal, all the commands sent by the script as the terminal received it. It was exactly what I needed and it is working perfectly for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.