我编写了一个 bash shell 脚本来重命名该文件,
#!/bin/bash
#renaming the files
for filename in 'find . -name "PostStackTemplate*"'
do
echo $filename
newName='echo $filename | sed -e "s/TestVersion/Version2/g" $filename'
mv $filename $newName
done
当我执行此脚本时,我得到的输出为
find . -name "PostStackTemplate*"
mv: invalid option -- n
Try `mv --help' for more information.
我是不是做错了什么?
最佳答案
我认为你应该使用command substitution将 sed
命令的输出分配给 newName
变量:
newName=$(echo $filename | sed -e "s/TestVersion/Version2/g" $filename)
否则,newName
将仅包含正在分配的字符串。
关于Shell 脚本错误 - 无法执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9185405/