Trying to access a bash array via function results in ${1[@]}: bad substitution -
there's not code below results in bad substitution.
#!/bin/bash numbers=(0 1 2 3 4 5 6 7 8 9) charslc=(a b c d e f g h j) charsuc=(a b c d e f g h j) show () { # value of var held in $1 in "${1[@]}"; echo $i done } # # processing happens here resulting in # var=numbers or # var=charslc or # var=charsuc # var=numbers # simulating process mentioned above show $var
question: how can fixed while ideally sticking type of approach?
define function as:
show() { arr=$1[@] in "${!arr}"; echo "$i" done }
and call as:
numbers=(0 1 2 3 4 5 6 7 8 9) var=numbers show "$var"
Comments
Post a Comment