我正在编写一个 shell 脚本,它在文件中找到给定的文本并从指定的路径替换它,并在替换文本后,用给定的单词重命名该文件。使用 sed 时出现权限被拒绝的错误。我的脚本看起来像这样
`echo "Please Insert the path of the folder"
read input_variable
read -p "You entered: $input_variable is correct y/n " yn
read -p "Enter the word to find = " word
read -p "Enter word to replace = " replace
case $yn in
[Yy]* ) find "${input_variable}" -type f -iname "${word}.*" | while read filename; do "`echo "${filename}" | sed -i 's/$word/$replace/g' ${filename}| sed -i 's/\$word/\$replace/' ${filename}`"; done ;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac`
我收到以下错误
bulk_rename.sh: 34: bulk_rename.sh: : 权限被拒绝
有什么建议么 ?
在@vijay 的建议更新了脚本之后
echo "Please Insert the path of the folder"
read input_variable
read -p "You entered: $input_variable is correct y/n " yn
read -p "Enter the word to find = " word
read -p "Enter word to replace = " replace
case $yn in
[Yy]* ) find "${input_variable}" -type f -iname "${word}.*" | while read filename; do
perl -pi -e 's/$word/$replace' ${filename}
mv ${filename} $word; done;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
现在我得到以下
替换替换未在 -e 第 1 行终止
这是我 chmod 并显示输出时得到的
abc@PC-DEV-41717:~/Documents/blog$ chmod +x bulk_rename.sh ; /bin/ls -l bulk_rename.sh
chmod +x bulk_rename.sh ; /bin/ls -l bulk_rename.sh
+ chmod +x bulk_rename.sh
+ /bin/ls -l bulk_rename.sh
-rwxrwxr-x 1 abc abc 1273 Aug 1 16:51 bulk_rename.sh