A variable can be all or part of any argument:
text
learner@tidepool:~$ DIR=~/shop/archive
learner@tidepool:~$ ls $DIR
2025 2026
learner@tidepool:~$ cp prices.txt $DIR/prices-$RELEASE.txtThe shell puts in each value, then the command starts.
${NAME}: show where the name ends
The shell reads letters, numbers and _ as part of the name, as far as it can:
| You type | The shell reads the name | Result for RELEASE=v2 |
|---|---|---|
$RELEASE_notes | RELEASE_notes | Empty |
${RELEASE}_notes | RELEASE | v2_notes |
$RELEASE.txt | RELEASE (. cannot be part of a name) | v2.txt |
${RELEASEthe name}_notestext after it
Values with spaces: use quotes
After the shell puts in the value, it splits the line at the spaces. A value with a space becomes two arguments:
text
learner@tidepool:~$ FILE="my notes.txt"
learner@tidepool:~$ cat $FILE
cat: my: No such file or directory
cat: notes.txt: No such file or directory
learner@tidepool:~$ cat "$FILE"
call the supplier on FridayPut double quotes around a variable when its value can have spaces. The next lesson shows why single quotes do not work here.