Skip to main content
Removed fluff, improved grammar and formatting
Source Link
Palec
  • 13.4k
  • 8
  • 74
  • 141

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):

  1. 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).
  2. echo $123 returning string as is to evalreturns the value of 123rd parameter, when evaluated.
  3. evaleval 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 :).

It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example this is part of my copy function:

eval echo $(echo '$'"$#")

to use in scripts do this:

a=$(eval echo $(echo '$'"$#"))

explanation:

  1. first most nested: $(echo '$'"$#") returns $[nr] where [nr] is number of parameters like $213 but in unevaluated string
  2. echo $123 returning string as is to eval
  3. eval just expands $123 to parameter, for example last_arg, and this is interpreted as string and returned

works with BASH shell as of mid 2015

cheers :)

This is part of my copy function:

eval echo $(echo '$'"$#")

To use in scripts, do this:

a=$(eval echo $(echo '$'"$#"))

Explanation (most nested first):

  1. $(echo '$'"$#") returns $[nr] where [nr] is the number of parameters. E.g. the string $123 (unexpanded).
  2. echo $123 returns the value of 123rd parameter, when evaluated.
  3. eval just expands $123 to the value of the parameter, e.g. last_arg. This is interpreted as a string and returned.

Works with Bash as of mid 2015.

deleted 8 characters in body
Source Link
esavier
  • 453
  • 4
  • 13

It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example this is part of my copy function:

copy()
{ 
 DEST=${$#}; #save last arg, it is always destination
 while [[ "$#" -gt 1 ]] #dont copy dest to $dest
 do
   cppriv $1 DEST  #some other function stuff
   shifteval #nexxtecho one$(echo please'$'"$#")

to use in scripts do this:

a=$(eval done
echo return$(echo 0
}'$'"$#"))

explanation: $# is number of parametsrs so by substitution : ${$#} will give something like this $123 - the last parameter given to shell script

  1. first most nested: $(echo '$'"$#") returns $[nr] where [nr] is number of parameters like $213 but in unevaluated string
  2. echo $123 returning string as is to eval
  3. eval just expands $123 to parameter, for example last_arg, and this is interpreted as string and returned

works with BASH shell as of mid 2015

cheers :)

It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example this is part of my copy function:

copy()
{ 
 DEST=${$#}; #save last arg, it is always destination
 while [[ "$#" -gt 1 ]] #dont copy dest to $dest
 do
   cppriv $1 DEST  #some other function stuff
   shift #nexxt one please
 done
 return 0
}

explanation: $# is number of parametsrs so by substitution : ${$#} will give something like this $123 - the last parameter given to shell script

works with BASH shell as of mid 2015

cheers :)

It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example this is part of my copy function:

eval echo $(echo '$'"$#")

to use in scripts do this:

a=$(eval echo $(echo '$'"$#"))

explanation:

  1. first most nested: $(echo '$'"$#") returns $[nr] where [nr] is number of parameters like $213 but in unevaluated string
  2. echo $123 returning string as is to eval
  3. eval just expands $123 to parameter, for example last_arg, and this is interpreted as string and returned

works with BASH shell as of mid 2015

cheers :)

Post Undeleted by esavier
Post Deleted by esavier
Source Link
esavier
  • 453
  • 4
  • 13

It is so simple, i dont udnerstand why all of you are proposing such a hacks: for example this is part of my copy function:

copy()
{ 
 DEST=${$#}; #save last arg, it is always destination
 while [[ "$#" -gt 1 ]] #dont copy dest to $dest
 do
   cppriv $1 DEST  #some other function stuff
   shift #nexxt one please
 done
 return 0
}

explanation: $# is number of parametsrs so by substitution : ${$#} will give something like this $123 - the last parameter given to shell script

works with BASH shell as of mid 2015

cheers :)