Bash has a niceis able to trace execution script commands with the -x command line option. Each command is then output to trace execution while debuggingstderr, prefixed by PS4 as stated in the man page.
-x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.
Albeit useful, the resolved executable path of each command is not given. So I have to figure out which executable has been run by guessing shell scriptsaliases and PATH value while reading execution trace.
For example, ruby has multiple command candidates on my workstation:
-x$ type Print-a commandsruby ruby andis their/home/cbliard/.rvm/rubies/ruby-2.1.0/bin/ruby ruby argumentsis as/home/cbliard/.rvm/bin/ruby ruby theyis are/usr/bin/ruby ruby executedis /home/cbliard/.rvm/bin/ruby It can be used when calling bashIf executing this script with /bin/bash -x script-file
#!/bin/bash echo -x"compute" ruby path/to/my/script/run_something.shrb echo "deploy" bundle install bundle exec cap deploy Or switched on and off duringTrace execution with set -x and set +xwill be
#!/bin/bash + echo "this"compute" compute + echoruby commandscript/run_something.rb [output isof notruby printed"script] #+ switchbundle oninstall setUsing -xrake (10.1.0) echoUsing "thisi18n one(0.6.9) [...] Your bundle is printedcomplete! Use before`bundle beingshow executed"[gemname]` to see where a bundled gem is installed. echo+ "thisbundle oneexec too"cap deploy # switch off triggering load callbacks set +x * 2014-01-14 09:12:42 executing `deploy' echo "but not* this2014-01-14 one"09:12:42 executing `deploy:update' [...] Finished: SUCCESS Running this little scriptI had some oddities with bash willresolved executables, mainly due to my usage of rvm. The output I would like is with fully resolved path, like this:
this+ [builtin] echo command"compute" compute + is/home/cbliard/.rvm/rubies/ruby-1.9.3-p484/bin/ruby notscript/run_something.rb [output printedof ruby script] + echo/home/cbliard/.rvm/gems/ruby-1.9.3-p484@global/bin/bundle 'thisinstall Using onerake is(10.1.0) Using printedi18n before(0.6.9) [...] Your beingbundle executed'is complete! thisUse one`bundle isshow printed[gemname]` beforeto beingsee executedwhere a bundled gem is installed. + echo/home/cbliard/.rvm/gems/ruby-1.9.3-p484@global/bin/bundle 'thisexec onecap too'deploy this one too triggering load callbacks + set +x* 2014-01-14 09:12:42 executing `deploy' but not this* one2014-01-14 09:12:42 executing `deploy:update' [...] Finished: SUCCESS Useful debugging output, but I'm missing a feature: knowing to which executableHaving the command has been resolved. My environment is using rvm. command would really help me debugging weird rvm stands for Ruby Version Manager and is an utility to install multiple ruby environments. So I installed multiple ruby environments. When I run a shell-script remotely, I see that /rubybundler get called but to be 100% sure that the good ruby has been called, I would like the full executable path to rubyissues.
I could do it by modifying the script and calling which here and there, but using a command-line option like The -x or something more hackish would really helpoption helps a lot but sometimes it is not enough. Is there any trick that helps knowing the full characteristics of the commands while running a bash script?. It is better if the original script does not have to be modified.