Shell programming: echo a variable

Quite often when I write shell scripts, I need to echo a variable for debugging.

If a is 'toto', I'd like to print:
a=toto

Of course, you can do

CODE:
  1. echo a=$a

But since I'm a programmer lazy, I'd like to:

CODE:
  1. echo_var a

How might you would write the echo_var function? (my solution in the comments)


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Shell programming: echo a variable”

  1. Here is my function

    CODE:
    1. # Echoes a variable like VAR=blabla
    2. # Argument is the variable name
    3. echo_var() {
    4.     local _dollaredvar='$'$1
    5.     printf "\$$1 = "
    6.     eval "echo $_dollaredvar"

Leave a Reply