简体   繁体   中英

linux shell script sed

#!/bin/sh -x

if [[ $# -eq 0 ]];then
   echo "usage: makeSoln <customer name>"
   exit
fi

echo "Customer Name is set to : $1"

if [ -d "$1" ]; then
    echo "Solution for $1 already exists!! Please delete it before running this."
    exit 1;
fi

if [ -e "$1" ]; then
    echo "A file by name '$1' exists!! Please delete it before running this."
    exit 1;
fi

cp -R SolnTemplate $1

cd $1

find . -name "pom.xml" | xargs sed -i xx 's/SolnTemplate/'$1'/g' 

When i given this and execute this file i am gettting this error:

+ xargs sed -e xx s/SolnTemplate/Reliance/g
sed: -e expression #1, char 2: extra characters after command

To begin, replace:

find . -name "pom.xml" | xargs sed -i xx 's/SolnTemplate/'$1'/g' 

With:

find . -name "pom.xml" | xargs sed -ixx 's/SolnTemplate/'$1'/g' 

The above removes the space between -i and xx . Because you are on Linux, you are using GNU sed and, unlike BSD sed, it does not accept a space between -i and the backup suffix.

Also, just in case $1 includes a space in the name, it should be enclosed in double-quotes:

find . -name "pom.xml" | xargs sed -ixx 's/SolnTemplate/'"$1"'/g' 

This still requires care that you don't unintentionally include any sed-active characters in $1 .

i didnt go over all of the script, but this command:

sed -i xx 's/SolnTemplate/'$1'/g'

should be:

sed -ixx 's/SolnTemplate/"$1"/g'

because the ' is from outside, you need to put in the inside "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM