Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bash/shell "set -x" sticky across nested calls to shell scripts

Tags:

bash

shell

I am trying to trace/debug a shell script that in turn includes nested invocations to other shell scripts.

My approach has been:

  • set -x (at the bash prompt)
  • add !/bin/bash -x to the main/entry point bash script

The second approach does end up showing the executions by the shell for the main script. But the nested scripts seem not to inherit that setting - either from the "set -x" on bash prompt or from the calling shell script.

Any way to achieve the inherited behavior - short of modifying each and every nested script?

like image 720
WestCoastProjects Avatar asked Aug 15 '14 21:08

WestCoastProjects


People also ask

What does %% mean in bash?

So as far as I can tell, %% doesn't have any special meaning in a bash function name. It would be just like using XX instead. This is despite the definition of a name in the manpage: name A word consisting only of alphanumeric characters and under- scores, and beginning with an alphabetic character or an under- score.

What does $() mean in shell script?

$() – the command substitution. ${} – the parameter substitution/variable expansion.

What is $_ in shell script?

The “$_” special variable can even be used for displaying the path of a Bash script in Ubuntu 20.04. It can do so if you create a simple Bash script and use the “$_” special variable before writing any other command in your Bash script. By doing so, you will be able to get the path of your Bash script very easily.


1 Answers

You can use the SHELLOPTS environment variable to make the "sub" shell use the same options. You just have to export it before any calls to subshells:

export SHELLOPTS
like image 112
MrTux Avatar answered Sep 24 '22 01:09

MrTux