Skip to content
Advertisement

How to include path inside bashrc in linux for envirnment

Im testing my code for automation of the installation of a software

In bashrc file below:

# User specific aliases and functions

export JAVA_HOME=/opt/jdk-9.0.1
export JRE_HOME=/opt/jdk-9.0.1/jre
export SCALA_HOME=/opt/scala-2.13.0
export PATH=$PATH:/opt/jdk-9.0.1/bin:/opt/jdk-9.0.1/jre/bin

Here im trying to add $SCALA_HOME/bin to PATH.

this is the required output:

 `export PATH=$PATH:/opt/jdk-9.0.1/bin:/opt/jdk-9.0.1/jre/bin:/opt/scala-2.13.0`

`sed -i '1n;/^export PATH/iexport SCALA_HOME=/opt/scala-2.13.0' .bashrc`

the above code worked to append SCALA_HOME above path but for appending in the same line im not able to do

`sed -i "s/"export PATH":.*,$/"export PATH": ":$SCALA_HOME/bin",/g" .bashrc
sed: -e expression #1, char 40: unknown option to `s'`

please help me get the correct sed command to append SCALA_HOME in the PATH

Advertisement

Answer

You can use this: sed '/export PATH/ s/$/:$SCALA_HOME/bin/' .bashrc

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement