为什么我的sedreplace为&执行失败?
我试图在Linux的Docker容器上运行以下命令,但我得到以下错误:
root@instance-0024c639:/etc/java-8-openjdk# sed -is/^assistive_technologies=/#&/ accessibility.properties [1] 1095 sed: -e expression #1, char 28: unterminated `s' command bash: /: Is a directory [1]+ Exit 1 sed -is/^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
我按照build议 – https://solveme.wordpress.com/2017/07/24/java-awt-awterror-assistive-technology-not-found-org-gnome-accessibility-atkwrapper-when-running-碧玉报告/
有人可以帮我吗?
只要引用这个命令,对Bash没有特别的意义!
sed -i 's/^assistive_technologies=/#&/' accessibility.properties # ^ ^
这里究竟发生了什么?
正如在man bash
读到的:
如果一个命令被控制操作符&终止,那么shell在一个子shell中在后台执行命令。
因此,当你说:
sed -is/^assistive_technologies=/#&/ accessibility.properties
Bash实际上看到两个命令:
sed -is/^assistive_technologies=/# / accessibility.properties
第一个是由&
发送到后台,所以你得到的消息:
[1] 1095
然后评估它,并确定它是不完整的,所以它触发错误:
sed: -e expression #1, char 28: unterminated `s' command
最后它显示了后台工作是如何完成的:
[1]+ Exit 1 sed -is/^assistive_technologies=/#
与此同时,它试图执行命令:
/ accessibility.properties
但惨败失败,因此它返回错误:
bash: /: Is a directory
你必须使用引号:
sed -i 's/^assistive_technologies=/#&/' accessibility.properties