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.
1.4m articles
1.4m replys
5 comments
57.0k users