haxxerz
haxxerz

Reputation: 953

Proper quoting for having sub-variables expand into their own parameters?

What's the best way to do

n=4
file1=firstfile.txt
file2=secondfile.txt
catlist="$file1" "$file2" 'file3.txt file'"$n"'.txt'

cat $catlist

Typically the gotchya with quoting is that you don't do enough. But I actually do want these to be their own parameters, so I'm not really sure how to go about this.

Upvotes: 1

Views: 69

Answers (1)

geirha
geirha

Reputation: 6171

Never put more than one argument into a single string; you need an array to hold multiple arguments.

catlist=( "$file1" "$file2" file3.txt "file$n.txt" )

cat "${catlist[@]}"

Upvotes: 2

Related Questions