我正在編寫一個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我已經嘗試更改權限,它給了我同樣的問題。 –