test_script.sh:#!/bin/shD1=$(dirname $0)echo $D1D0=(dirname $0)echo $D0What I type on the command line:$ ./test_script.shOutput:.(dirname ./test_script.sh)What significance does the first dollar sign in D1's value have s.t. the command gets executed while D0's value is interpreted as a string?
why does the dollar sign cause this command to be executed?
shell script;scripting;variable substitution;variable;subshell
A trivial search for $( in the shell man page gives the answer.As $name causes parameter expansion $(command) causes command substitution i.e. it is replaced by the output of the command (with trailing newline(s) removed). $(command) causes word splitting after the expansion, $(command) avoids it (like $name vs. $name).(dirname) on the other hand is just a literal string to the shell.