3.9 Variables
Dealing with variables in Bash takes some getting used to, especially if you have worked in other, “higher-level” programming languages. I want to start with three basic rules:
-
Variable names must usually be preceded by a dollar sign when analyzed (when reading), but not when assigned (when writing). As you’ll see, exceptions to this rule exist.
-
With the myvar=value assignment, no blanks are allowed before and after the = character.
-
Bash variables usually store strings. (Yes, Bash can also handle numbers and even supports arrays. But these are special cases, some of which require syntactic acrobatics.)
The first example illustrates the handling of variables. Explanations of the if construct with the -gt comparison operator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access