收到 sed 错误

发布于 2024-12-08 14:56:07 字数 530 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-12-15 14:56:07

鉴于 sed 似乎认为您正在运行 delete line 命令 (d),您可能需要输出该命令以查看实际内容您的环境变量中:

for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
    echo sed -i "s/HOSTNAME/${PSM_SERVER_ADDRESS}/g" $fl
done

PSM_SERVER_ADDRESS 很有可能正在破坏您的 sed 命令(并且可能需要进行处理以使其干净) )。执行此操作的一种方法(前提是您有足够新的 sed)是使用环境变量中未出现的分隔符,例如:

sed -i "s?HOSTNAME?${PSM_SERVER_ADDRESS}?g" $fl

既然您已经接受了这个答案,我也可以添加您发现的其他问题的解决方案。与 Linux 不同,BSD sed 似乎要求您为 -i 选项提供扩展。因此,虽然 Linux 允许:

sed -i "sed-command"

就地编辑,但 BSD 变体需要:

sed -i "" "sed-command"

具有空的备份后缀。

否则,sed 可能会使用您的命令作为扩展名,并使用您的第一个文件名作为命令。

Given that sed seems to think you're running a delete line command (d), you may want to output the command to see what's actually in that environment variable of yours:

for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
    echo sed -i "s/HOSTNAME/${PSM_SERVER_ADDRESS}/g" $fl
done

There's a good chance the PSM_SERVER_ADDRESS is corrupting your sed command (and may need to be processed to make it clean). One way to do this (provided you have a recent enough sed) would be to use delimiters that do not appear in the environment variable, for example:

sed -i "s?HOSTNAME?${PSM_SERVER_ADDRESS}?g" $fl

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:

sed -i "sed-command"

to edit in-place, the BSD variant needs to have:

sed -i "" "sed-command"

with an empty backup suffix.

Without that, sed may use your command as the extension and your first file name as the command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文