linux - Bash parameter reference -


i want refer parameter in bash using number generated sum. how do this?

more specifically:

    #!/bin/bash      $sum=${$1}     echo $sum 

when execute script ./script.bash b c d, if $sum = 3, want return c. how do this, know?

you can use indirect expansion syntax:

${!parameter}

as described here.

(also note variable assignments should not have $ on left-hand side!)

example:

$ cat script.bash  #!/bin/bash  sum=3 arg=${!sum} echo $arg $ ./script.bash b c d c $ 

Comments

Popular posts from this blog

sql - text truncated using perl DBI insert -

c++ - Is it possible to compile a VST on linux? -

php - Pass object by reference or value -