Skip to content

Commit 6e93585

Browse files
portable sed replacement when creating new recipes (#234)
* portable sed replacement when creating new recipes * Fix typo Co-authored-by: Jordan Martinez <[email protected]>
1 parent 8b044ff commit 6e93585

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

scripts/newRecipe.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,27 @@ set -x
3434
# Copy original recipe to new recipe directory
3535
cp -r recipes/$orig recipes/$1
3636

37-
# Replace all usages of the original recipe's name with the new recipe's name
38-
grep -rl $orig recipes/$1 | xargs sed -i "s/$orig/$1/g"
37+
# Disable echo of all following script commands.
38+
# We used to be able to echo the substitution one-liner,
39+
# but the portable version is now too verbose.
40+
set +x
3941

42+
# Replace all usages of the original recipe's name with the new recipe's name
43+
echo "+ Substituting all occurrences of $orig in recipes/$1"
44+
for file in $(grep -rl $orig recipes/$1)
45+
do
46+
sed "s/$orig/$1/g" $file > $file.new
47+
mv $file.new $file
48+
done
49+
# This used to be as simple as:
50+
# grep -rl $orig recipes/$1 | xargs sed -i "s/$orig/$1/g"
51+
# But there are portability issues with in-place substitution (-i)
52+
# between the GNU (most linux distros) and BSD (mac osx) versions of `sed`.
53+
# See https://stackoverflow.com/a/21243111 for details.
4054

4155
# ====== Additional instructions =======
4256

43-
# Disable echo of all following script commands
44-
set +x
45-
57+
echo # linebreak
4658
echo --- Some helpful development commands for this recipe: ---
4759

4860
# Basic node

0 commit comments

Comments
 (0)