startpilot
という単語が1行に複数回出現する可能性があるため、sed
を最大3回起動する必要があります。私はこのスクリプトがはるかに優れていると思うかもしれませんが、おそらく誰も私がそれを最適化するのを助けることができます。シェルスクリプトでsedの検索と置換を最適化する方法
grep -rl "startpilot" ./* -R | xargs sed -i '' "s/startpilot/${PWD##*/}/"
#! /bin/bash
DIR="$1"
if [ $# -ne 1 ]
then
echo "Usage: $0 {new extension key}"
exit 1
fi
if [ -d "$DIR" ]
then
echo "Directory/extension '$DIR' exists already!"
else
git clone https://github.com/misterboe/startpilot.git $DIR --depth=1
echo "$DIR created."
cd $DIR && rm -rf .git && grep -rl "startpilot" ./* -R | xargs sed -i '' "s/startpilot/${PWD##*/}/" && grep -rl "startpilot" ./* -R | xargs sed -i '' "s/startpilot/${PWD##*/}/" && grep -rl "startpilot" ./* -R | xargs sed -i '' "s/startpilot/${PWD##*/}/" && grep -rl "Startpilot" ./* -R | xargs sed -i '' "s/Startpilot/${PWD##*/}/"
cd Resources/Public/ && bower install
echo "Your extension is now in $DIR."
fi
'///'に'/g'修飾子が必要ですか? – choroba