Add line at the end of the file with the sed command

Asked

Viewed 2,121 times

0

I am configuring a virtual machine to install JDK 7, Tomcat 7, Jboss EAP 7 and Postgresql. Follow the project on Github for anyone interested: cresol-enviroment-Vagrant.

I’m at the part where you need to add the JAVA_HOME in the archive /etc/profile, but when executing the following command:

sudo sed -i 'JAVA_HOME=/usr/lib/jvm/jdk7u79' /etc/profile

Is returning the error message:

sed: -e Expression #1, char 1: Unknown command: `J'

How can I add lines that refer to the JDK directory path correctly?

References:

Installation and Configuration of JDK 7

3 answers

4

You can also solve this problem without using the sed:

sudo echo $JAVA_HOME=/usr/lib/jvm/jdk7u79 >> /etc/profile
  • 2

    (+1) but it seems to me that the $a is the most.

  • Right, @Jjoao. Thanks for the warning.

1

sudo sed -i -e '$aJAVA_HOME=/usr/lib/jvm/jdk7u79' /etc/profile

0

You can do something like this:

echo 'JAVA_HOME=/usr/local/java
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH' >> /etc/profile

See more in mine script in gist.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.