I'm trying to write a bash script that read user's input (some files so user can use TAB completion) and copy them into a specific folder.
#/bin/bash read -e files for file in $files do echo $file cp "$file" folder/"$file" done It's ok for: file1 file2 ...
Or with : file* (even if there is a filename with space in the folder).
But it's not working for filenames with space escaped with backslash \ like : file\ with\ space escaped spaces are ignored and string is split on each spaces, even escaped.
I saw information on quoting, printf, IFS, read and while... I think it's very basic bash script but I can't find a good solution. Can you help me?
$files(eg. for file in "$files")?for file in "$files"point makes the loop useless -- it'll only iterate once, over the exact and entire content of$files; might as well not have a loop at all in that case."$@"to get the exact names and not deal with any of this mess. Easier to automate when calling from other scripts that way, as well.