It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example thisThis is part of my copy function:
eval echo $(echo '$'"$#")
toTo use in scripts, do this:
a=$(eval echo $(echo '$'"$#"))
explanationExplanation (most nested first):
- first most nested:
$(echo '$'"$#")
returns$[nr]
where [nr][nr]
is the number of parameters like $213 but in unevaluated. E.g. the string$123
(unexpanded). echo $123
returning string as is to evalreturns the value of 123rd parameter, when evaluated.- eval
eval
just expands $123$123
to the value of the parameter, for examplee.g.last_arg
, and this. This is interpreted as a string and returned.
worksWorks with BASH shellBash as of mid 2015
cheers :).