I have a bash script like:
files="${@:2}"
for f in $files; do
echo $f
done
which takes the shell expansion from the second argument to the last, and print it. However it does not work with files with spaces. It prints files:
test image.jpg
as
test
image.jpg
If I use:
for f in "${@:2}"; do
echo $f
done
without assigning it to $files, it works fine.
I also tried to use the first case with quoted "$files"
, and does not work. It prints all files in one line. How can I assign the file names to another variable, while still making it work when using expansion like for in loop?