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
Post a Comment