gpt4 book ai didi

linux - 为什么我的 sed 替换为 & 无法执行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:39 26 4
gpt4 key购买 nike

我试图在 Linux Docker 容器上运行以下命令,但出现以下错误:

root@instance-0024c639:/etc/java-8-openjdk# sed -i s/^assistive_technologies=/#&/ accessibility.properties
[1] 1095
sed: -e expression #1, char 28: unterminated `s' command
bash: /: Is a directory
[1]+ Exit 1 sed -i s/^assistive_technologies=/#

我运行它的文件内容:

root@instance-0024c639:/etc/java-8-openjdk# cat accessibility.properties
#
# The following line specifies the assistive technology classes
# that should be loaded into the Java VM when the AWT is initailized.
# Specify multiple classes by separating them with commas.
# Note: the line below cannot end the file (there must be at
# a minimum a blank line following it).
#
assistive_technologies=org.GNOME.Accessibility.AtkWrapper

我按照建议去做 - https://solveme.wordpress.com/2017/07/24/java-awt-awterror-assistive-technology-not-found-org-gnome-accessibility-atkwrapper-when-running-jasper-reports/

有人可以帮我吗?

最佳答案

只是引用命令所以 & 对 Bash 没有特殊意义!

sed -i 's/^assistive_technologies=/#&/' accessibility.properties
# ^ ^

这里到底发生了什么?

正如在 man bash 中所读:

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell.

因此,当你说:

sed -i s/^assistive_technologies=/#&/ accessibility.properties

Bash 实际上看到了两个命令:

sed -i s/^assistive_technologies=/#
/ accessibility.properties

第一个是&发送到后台的,所以你得到消息:

[1] 1095

然后它评估它并确定它不完整,因此它触发错误:

sed: -e expression #1, char 28: unterminated `s' command

最后它显示了后台作业是如何完成的:

[1]+  Exit 1                  sed -i s/^assistive_technologies=/#

与此同时,它尝试执行命令:

/ accessibility.properties

但失败得很惨,因此返回错误:

bash: /: Is a directory

关于linux - 为什么我的 sed 替换为 & 无法执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47199479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com