I'm pretty new to bash,
I learned about using variables like this:
var=$(cat << EOF
this is echoed
and this as well...
EOF
)
echo "$var"
if the above code is called using a variable
how do you call the approach below? is this called a using a definition
?
def="This should be echoed\nand this as well...\n"
printf "$def"
I'm asking about the right terminology of the second approach.
Both var
and def
are variables; that is, they are the names of string-data in your current environment, accessed using $
as in your examples.
To create each variable, you assign a string to it. This is called an assignment. Syntactically, =
is the assignment operator.
Once var
and def
are assigned, there is no difference in how they store data; the stored data in each case is merely a string.
There is nothing "special" requiring additional terminology in the assignment of def
. However, there are two interesting aspects of the var
assignment:
cat
is a pattern called a "here document".$()
, which is a form of "command substitution".