收到 sed 错误
我是 shell 脚本编写的新手,但收到此错误并且无法弄清楚发生了什么。
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
这是我正在运行的脚本
for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
sed -i "s/HOSTNAME/${IP_ADDRESS}/g" $fl
done
谢谢
I'm new to shell scripting but getting this error and cant figure out what up.
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
sed: 1: "/Users/local/Do ...": extra characters at the end of d command
Here is the script I'm running
for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
sed -i "s/HOSTNAME/${IP_ADDRESS}/g" $fl
done
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于
sed
似乎认为您正在运行delete line
命令 (d
),您可能需要输出该命令以查看实际内容在您的环境变量中:PSM_SERVER_ADDRESS
很有可能正在破坏您的sed
命令(并且可能需要进行处理以使其干净) )。执行此操作的一种方法(前提是您有足够新的sed
)是使用环境变量中未出现的分隔符,例如:既然您已经接受了这个答案,我也可以添加您发现的其他问题的解决方案。与 Linux 不同,BSD
sed
似乎要求您为-i
选项提供扩展。因此,虽然 Linux 允许:就地编辑,但 BSD 变体需要:
具有空的备份后缀。
否则,
sed
可能会使用您的命令作为扩展名,并使用您的第一个文件名作为命令。Given that
sed
seems to think you're running adelete line
command (d
), you may want to output the command to see what's actually in that environment variable of yours:There's a good chance the
PSM_SERVER_ADDRESS
is corrupting yoursed
command (and may need to be processed to make it clean). One way to do this (provided you have a recent enoughsed
) would be to use delimiters that do not appear in the environment variable, for example:Since you've accepted this answer, I may as well add the resolution for the additional problem you found. It appears that BSD
sed
, unlike Linux, has a requirement that you provide an extension to the-i
option. So, while Linux allows:to edit in-place, the BSD variant needs to have:
with an empty backup suffix.
Without that,
sed
may use your command as the extension and your first file name as the command.