Providing parameter defaults
Within bash parameters, there are named spaces in the memory that allow us access to stored values. There are two types of parameters:
- Variables
- Special parameters
Variables
We already described what variables are and how to define them in Chapter 1, The What and Why of Scripting with Bash.
Just to refresh your memory, you can define a variable by assigning a value with an equals sign and without any spaces like this:
#!/bin/bash myvar=15 myvar2="welcome"
So nothing new here.
Special parameters
Special parameters are the second parameter type and are managed by the shell itself and are presented as read-only. We have come across these before in parameters such as $0
but let's take a look at another $-
. We can expand these parameters to gain an understanding of their use, using the echo
command:
$ echo "My shell is $0 and the shell options are: $-"
From the annotated text that I have added, we can understand that the $-
option represents the shell options that are configured...