Yes, there is a difference between '$(x)', '${x}', $x and x.
'$(x)' executes x as a command and replaces $(x) in the command with the standard output of x. This could also be written as '`x`' (enclosing the command in backticks). This is the older way of writing a command substitution. It's somewhat frowned on because the new way is easier to read.
'${x}' and '$x' will get substituted with the value of the variable x. The latter variant is shorter but won't always work as expected if used to construct some kind of string; there needs to be a space or a newline after $x so the shell can recognize the end of the variable name, with ${x} that's not necessary. To check the value of a variable enter something like "echo ${BUILD_SRC}".
And if you look at the commands given in those build instructions, you can tell why they are doing it this way: they store the current working directory in BUILD_SRC and then they are changing directory. The value of BUILD_SRC keeps the old working directory.
Code:
$ BUILD_SRC=$(pwd)
$ BUILD_SRC # execute literal 'BUILD_SRC'; there's no such command ...
BUILD_SRC : command not found
$ {BUILD_SRC} # the same; in both cases there's a '$' missing; if it was there you'd get a different error
BUILD_SRC : command not found
$ ${BUILD_SRC} # actually substituting the variable value for it's name
bash: /home/jv/dirname is a directory
but:
$ a="echo x" # assign a string that is a valid command to a variable
$ $a # the value of $a is substituted and executed
x
Holger
Edit: Slow typists get ninja'd. Hi, Impavidus !
Bookmarks