我正在编写一个shell脚本,它在文件中查找给定的文本并将其替换为指定的路径,并在替换文本之后,将该文件重命名为与给定的词。 我在使用sed时遇到拒绝权限错误。我的脚本看起来像这样使用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并显示输出
[email protected]:~/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
'使用chmod + X bulk_rename.sh' – devnull
也许你没有权限编辑有问题的文件。 – devnull
感谢您的快速回复@devnull我已经尝试更改权限,它给了我同样的问题。 –