Shell 脚本错误 - 无法执行命令

标签 shell

我编写了一个 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 substitutionsed 命令的输出分配给 newName 变量:

newName=$(echo $filename | sed -e "s/TestVersion/Version2/g" $filename)

否则,newName 将仅包含正在分配的字符串。

关于Shell 脚本错误 - 无法执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9185405/

相关文章:

linux - 根据扩展名识别文件

bash - 如何在posix环境中运行bash shell脚本?

windows - 使用 Windows 命令行查看文件是否存在并重命名

linux - 有没有办法找到shell中最后执行的命令的运行时间?

shell - "sh -c ' some command'"和直接运行some命令有什么区别

bash - 如何读取 Bash 脚本中的多行输入?

linux - 如何更改 child 目录中的文件名

java - Jenkins运行远程shell脚本的问题

xml - CURL 无法通过命令行发送超过 1024 字节的发布数据

linux - 如何在 Linux 中使用命令锁定显示器?