Quotidien Shaarli

Tous les liens d'un jour sur une page.

06/03/22

Dynamic variable names in Bash - Stack Overflow
thumbnail
# check that name is a valid variable name:
# note: this code does not support variable_name[index]
shopt -s globasciiranges
[[ "$name" == [a-zA-Z_]*([a-zA-Z_0-9]) ]] || exit

value='babibab'
eval "$name"='$value'  # carefully escape the right-hand side!
echo "$var_37"  # outputs “babibab”