Skip to content
Advertisement

Why is my sed substitution with a & failing to execute?

I am trying to run following command on Linux Docker container but I am getting the following error:

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=/#

The file content I am running it for:

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

I am doing it as suggested at – https://solveme.wordpress.com/2017/07/24/java-awt-awterror-assistive-technology-not-found-org-gnome-accessibility-atkwrapper-when-running-jasper-reports/

Can someone help me with it?

Advertisement

Answer

Just quote the command so & does not have an special meaning for Bash!

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

What is exactly happening here?

As read in man bash:

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

Thus, when you say:

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

Bash is actually seeing two commands:

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

The first is sent to the background by &, so you get the message:

[1] 1095

Then it evaluates it and determines it is incomplete, so it triggers the error:

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

Finally it shows how the background job has finished:

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

In the meanwhile, it tries to execute the command:

/ accessibility.properties

But fails miserably and hence it returns the error:

bash: /: Is a directory
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement