I am scripting my new VM stack and I am trying to update or append JAVA_HOME in the ~/.bashrc file
I've managed to do that by running the following sed command from the command line.
sed '/export[ ]JAVA_HOME=/{h;s/=.*/='"updatedJava"'/};${x;/^$/{s//export JAVA_HOME='"newJava"'/;H};x}' -i ~/.bashrc However, when I try to run it from a script using a variable, I am getting the following error:
sed: -e expression #1, char 34: unknown option to `s'
I figured out that it is caused due to fact that my path contain / which is confused with the sed delimiter, therefore I've changed it to this:
sed '/export[ ]JAVA_HOME=/{h;s#=.*#='$java'#};${x;/^$/{s##export JAVA_HOME='$java'#;H};x}' -i ~/.bashrc where $java contains a path to java, however now it doesn't work, it also doesn't throw any exception. Where did I make a mistake?