Cannot evaluate script arguments from function
I've started writing shell scripts again and I've found myself in a
situation where I frequently have to write debug echo's to trace what the
script is doing. The, easy, way I used to do this right was to write
something like this :
#!/bin/bash
myVar = 'Erractic Nonesense'
echo "myVar: $myVar"
==> myVar: Erractic Nonesense
This worked great and was fairly simple but, having to write this for
every variable I wished to trace was tiring and as a person who thinks
that having less code to do more stuff is great, I wrote myself a
function:
#!/bin/bash
function dbg # $msg
{
echo "$@: ${!@}"
}
myVar = 'Erractic Nonesense'
dbg myVar
==> myVar: Erractic Nonesense
This works great for regular variables but, for the scripts arguments ($1,
$2, etc.), does not work. Why?
==> $ ./myScript 123
#!/bin/bash
...
dbg 1 # This is the bugger in question.
==> 1: 1
No comments:
Post a Comment