Overwrite internal field separator when replacing.

Problem:
Currently the `for` in bash will break up lists by whitespace, so if a
filename has a space in it the `for` will break it up incorrectly.

AG will separate the files with a newline character, so this temporarily
overwrites the `IFS` to be used correctly for this use case.

[Docs](https://bash.cyberciti.biz/guide/$IFS)
This commit is contained in:
Blaine Schmeisser 2016-04-08 09:01:22 -07:00 committed by Geoff Harcourt
parent f25b410bba
commit 1dc550d985

View file

@ -11,6 +11,7 @@ shift
items=$(ag -l --nocolor "$find_this" "$@")
temp="${TMPDIR:-/tmp}/replace_temp_file.$$"
IFS=$'\n'
for item in $items; do
sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item"
done