开发者

How to view the command executed in a script as it is executed?

开发者 https://www.devze.com 2023-01-26 00:57 出处:网络
I have a bash script I\'ve written to automate something tedious, so I got the command looking right in echo, but when I run it, it doesn\'t work. This is what I\'m doing:

I have a bash script I've written to automate something tedious, so I got the command looking right in echo, but when I run it, it doesn't work. This is what I'm doing:

CMD='custom_script update --flag=value --com开发者_如何学编程ment="testing"'
echo -e "Running $CMD"
$CMD

The echo shows: custom_script update --flag=value --comment="testing"

which is correct, but that is not what is actually run with the $CMD line (I know because if I copy and paste the output from echo, it works, but the error message after running in the script suggests the quoting is off).

I think I can figure this out if I can see the command run by $CMD, but I don't know how to do that.


Run it like

bash -x script.sh

or modify the shebang like

#!/bin/bash -x


Looks like

eval $CMD

is what I needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消