f1="filename1"; i=1; c=f$i echo $c
What shell command should I use so that echo $c returns "filename1" as the output?
echo $c
Use variable indirection.
#!/bin/bash f1="filename1"; i=1; c=f$i echo ${!c}
It works in bash ( GNU bash, version 4.1.2(1)-release ). I have not tried in other shells.
2.1m questions
2.1m answers
60 comments
57.0k users