Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command inside $() in bash script

I'm new to linux. I'm seeing a bash command (is that even the right term?) that sets JAVA_HOME environment variable at the prompt:

export JAVA_HOME =$(readlink -f /usr/bin/java |sed "s:bin/java::")

I know what the command inside $() does. But what is the $() for? It failed if I didn't include it.

Obviously googling $() doesn't work very well.

like image 255
Bajingan Keparat Avatar asked Feb 20 '23 14:02

Bajingan Keparat


1 Answers

$() is called command substitution. It replaces the output of a command with the command itself. There are basically two ways you can do command substitution:

$(command)

or with backticks

`command`

The first variant is the preferred one.

You can read more about command substitution here.

like image 130
Kai Sternad Avatar answered Feb 27 '23 20:02

Kai Sternad