deducing the name of the variable from positional parameters in a posix shell -
#!/bin/sh foo() { printf "$1" } random_var="hello\n" foo $random_var
when pass 1 or more variables function, in case foo
, accessible through $1
$2
, on; how go step inside foo
, print name of original variable in case means random_var
?
succinctly, don't or can't tell inside function variables used create argument function. there's no guarantee argument variable, or single variable — example:
foo 123 foo ${home}:${path}
further, if function cares, mis-written. should self-contained possible, , therefore independent of such issues. if isn't, suggests maybe function not functionally cohesive.
Comments
Post a Comment