Skip to content

Commit

Permalink
Overwrite internal field separator when replacing.
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Blaine Schmeisser authored and geoffharcourt committed Apr 15, 2016
1 parent f25b410 commit 1dc550d
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions bin/replace
Expand Up @@ -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

0 comments on commit 1dc550d

Please sign in to comment.