Let's take one command at a time:
echo $ABCHOME
The $
is a unary operator which indicates that expansion (or "substitution" if you like) is to take place. With no brackets it gives the value of the variable which follows. If the variable value contains whitespace then that whitespace will be used as an argument separator to the command, so I recommend:
echo "$ABCHOME"
Note: double quotes not single. Like brackets, different quote characters have different uses.
Using { }
:
echo ${ABCHOME}
With no other characters, the braces are used to delimit the variable name when embedded in other text, and are rarely required (although they are benign). For example: echo "$ABCHOMEandaway"
would fail, but echo "${ABCHOME}andaway"
would append "andaway" to the value text. The recommendations with quotes also apply here.
Braces, ${ }
also introduce other variable expansion syntax when the variable name is followed by a special character like a colon :
or a /
. That is probably too advanced for you right now, put that on your list for learning later.
Using $( )
:
echo $(ABCHOME)
This expansion is command substitution, where the command specified inside the parentheses is run and the standard output captured and returned to the script. Of course, there is no command called ABCHOME
, so you get:
bash: ABCHOME: command not found
As a general rule, brackets cannot be exchanged without thought in any programming language. Bash syntax can be complex and non-intuitive. Follow a tutorial (there are lots available). Play by all means, but use the man bash
pages to discover the syntax you are using.