获取 sed 错误 [英] Getting sed error
问题描述
我是 shell 脚本的新手,但遇到此错误并且无法弄清楚发生了什么.
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
这是我正在运行的脚本
for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
sed -i "s/HOSTNAME/${IP_ADDRESS}/g" $fl
done
谢谢
推荐答案
鉴于 sed
似乎认为您正在运行 delete line
命令 (d
),您可能希望输出命令以查看在您的环境变量中的实际内容:
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
PSM_SERVER_ADDRESS
很有可能会破坏您的 sed
命令(并且可能需要对其进行处理以使其干净).执行此操作的一种方法(前提是您有足够新的 sed
)是使用未出现在环境变量中的分隔符,例如:
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
<小时>
既然您已经接受了这个答案,我不妨为您发现的其他问题添加解决方案.似乎 BSD sed
与 Linux 不同,它有一个要求,即您提供对 -i
选项的扩展.因此,虽然 Linux 允许:
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"
要就地编辑,BSD 变体需要:
to edit in-place, the BSD variant needs to have:
sed -i "" "sed-command"
带有空的备份后缀.
否则,sed
可能会使用您的命令作为扩展名,并使用您的第一个文件名作为命令.
Without that, sed
may use your command as the extension and your first file name as the command.
这篇关于获取 sed 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!