BASH Shell Features
BASH Shell Features
Linux contains many different shells, but we will focus on the BASH shell. A majority of these concepts will transfer between shells, though each shell does have its differences. If you do decided eventually to change shells you should read about it prior to changing.
This part of the module will help with learning to code shell scripts. Before we start to code shell scripts we first need to understand how to create variables and access them. Recall that a variable is a character string that we assign a value. We can then access that value to manipulate it or use it as required.
Viewing Variable Values, Creating & Deleting
To view a variable value you need to use the echo command with the name of the variable. For example:
echo $PATH
This will show you the value of the PATH variable. Notice, that we need to include a $ in front of the variable name or it will just display the string of text.
To create our own variable we use the syntax:
VARIALBENAME=value_of_variable
You should always create your variable names as all capital letters. This helps to identify that they are a variable. If we wished to create a variable called COURSE and assign it a value of ics231 we would do the following:
COURSE=ics231
Notice we do not have spaces, this would cause an error!
To delete a variable we would use the unset command. The syntax of this command is:
unset VARIABLENAME
For us to delete the COURSE variable we'd enter the following:
unset COURSE
printenv
The printenv command provides an easy method to display all your environmental variables.
https://linux.die.net/man/1/printenv
export
By default when you create a shell variable (as we have been doing) it will not be available to a child process. If we wish to make it available to be used by a child process we need to use the export command. This command will make the variable available to the child process.