0

I saw these instructions in a book and don't know what the . /etc/profile command does, what is it?

Is it the same as source /etc/profile?

Linux-specific Java steps

On Linux systems, the following instructions set up a bash file in the /etc/profile.d/ directory that defines JAVA_HOME for all users. Changing environmental settings in this folder requires root access and affects all users of the system. (We’re using $ as the bash shell prompt.) The Oracle JVM installer typically installs the software in /usr/java/ jdk-1.6.X (for v1.6) and it creates sym-links from /usr/java/default and /usr/java/latest to the installation:

$ /usr/java/latest/bin/java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
$ sudo echo "export JAVA_HOME=/usr/java/latest" > /etc/profile.d/java.sh
$ sudo echo "PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile.d/java.sh
$ . /etc/profile
$ echo $JAVA_HOME
/usr/java/latest
muru
  • 72,889

1 Answers1

2

Yes, . /etc/profile is the same as source /etc/profile as you said. It means the commands in the file will be executed as they were executed in cli, and not in a new subshell as with standard script being called.

https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html

3.5. Sourcing a File When a file is sourced (by typing either source filename or . filename at the command line), the lines of code in the file are executed as if they were printed at the command line. This is particularly useful with complex prompts, to allow them to be stored in files and called up by sourcing the file they are in.

In examples, you will find that I often include #!/bin/bash at the beginning of files including functions. This is not necessary if you are sourcing a file, just as it isn't necessary to chmod +x a file that is going to be sourced. I do this because it makes Vim (my editor of choice, no flames please - you use what you like) think I'm editing a shell script and turn on colour syntax highlighting.

ralz
  • 1,996
  • 13
  • 17