mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup shell scripts, BUG: unclosed 'if' in inlineReplace
This commit is contained in:
@ -1,31 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
# $0 string1 string2 file1 .. filen
|
||||
# $0 oldString newString file1 .. fileN
|
||||
#
|
||||
if [ $# -lt 3 ]
|
||||
then
|
||||
echo "Usage: ${0##*/} [-f] <string1> <string2> <file1> .. <filen>"
|
||||
echo "Usage: ${0##*/} <oldString> <newString> <file1> [.. fileN]"
|
||||
echo ""
|
||||
echo "Replaces all occurrences of string1 by string2 in files."
|
||||
echo "(replacement of sed -i on those systems that don't support it)"
|
||||
echo "Replaces all occurrences of oldString by newString in files."
|
||||
echo "(replacement for sed -i on systems that don't support it)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FROMSTRING=$1
|
||||
shift
|
||||
TOSTRING=$1
|
||||
shift
|
||||
oldString="$1"
|
||||
newString="$2"
|
||||
shift 2
|
||||
|
||||
for f in $*
|
||||
for f
|
||||
do
|
||||
if grep "$FROMSTRING" "$f" >/dev/null
|
||||
if grep "$oldString" "$f" >/dev/null
|
||||
then
|
||||
cp "$f" "${f}_bak"
|
||||
sed -e "s@$FROMSTRING@$TOSTRING@g" "${f}"_bak > "$f"
|
||||
rm -f "${f}"_bak
|
||||
sed -e "s@$oldString@$newString@g" "${f}_bak" > "$f"
|
||||
rm -f "${f}_bak"
|
||||
#else
|
||||
# echo "String $FROMSTRING not present in $f"
|
||||
#fi
|
||||
# echo "String $oldString not present in $f"
|
||||
fi
|
||||
done
|
||||
|
||||
# ----------------------------------------------------------------- end-of-file
|
||||
|
||||
Reference in New Issue
Block a user