I have some command foo that produces a list of files (one per line).
foo
I'd like to safely use that in command substitution; e.g. git checkout ... -- $(foo). Since filenames can have special characters and spaces, I'd like to avoid any word-splitting or other issues.
git checkout ... -- $(foo)
What's a good way to go about this? Keep in mind I anticipate needing to do this quite a bit, so it'd be nice to have a solution that's not janky (interpret however you like.)
IFS can be set to respect spaces when making arrays:
IFS
IFS=$' ' eval 'FILES=($(foo))'
Finally, this can be used in the script as needed by doing:
git checkout ... -- "${FILES[@]}"
1.4m articles
1.4m replys
5 comments
57.0k users