views:

20

answers:

4

How can you display how a bash script would look like with the variables expanded?

I want see how what the script would actually execute, without doing any damage.

A: 

prefix your commands with echo?

Benoit
A: 

You can use the -x option of bash as:

$bash -x myscript.sh
codaddict
A: 

There are three relevant options:

  • -n - do not execute
  • -v - show the code as it is read
  • -x - show the code as it is executed

AFAIK, you can't see the expanded variables with -n in effect, but you can't avoid executing code unless -n is in effect. So, roughly, you have to execute the script to see the expanded variables.

Jonathan Leffler
A: 

If you don't execute the variable assignments then there's nothing to expand.

Dennis Williamson