Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does export variable without an equals sign do?

Tags:

bash

There's a bash script on my linux machine with these two lines:

[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME

What does the export JAVA_HOME do? Usually I thought export VARIABLE_NAME=something sets the variable to something.

What does running export JAVA_HOME without setting it to something do?

I tried running it on the commandline, but nothing happens.

like image 344
leontp587 Avatar asked Jun 11 '26 11:06

leontp587


1 Answers

The two lines of code (better to use double brackets):

[[ -r /etc/java/java.conf ]] && . /etc/java/java.conf
export JAVA_HOME

...equates to this:

-r checks if /etc/java/java.conf exists and read permission is granted.

&& if the condition above is true then source the file.

export JAVA_HOME takes the previously-assigned value of $JAVA_HOME from the sourced file making it available to subprocesses rather than only within the shell.

  • What does "export" do in shell programming?
  • What does "source" do?
  • Conditional statements in bash
like image 138
l'L'l Avatar answered Jun 13 '26 00:06

l'L'l



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!