Linux Mint Shell Scripting Primer : Part III

[ This is a five part series that covers the very basics of Linux shell scripting. For the very beginning, start from Part I here.]

In the previous part, we had seen how to display user friendly messages and information using the echo command along with popular Terminal commands.

From this part onwards, there will be lots of fun stuff, the heart of shell scripting using variables, loops and user interaction. Let’s take a look at what variables are in this part when it comes to shell scripting.

Writing shell scripts is a sort of programming itself with Linux shell following it’s own rules and syntax. Variables, loops and user interaction are the heart of any shell script.

Variables help you store temporary information which can be retrieved later in the script. Consider this simple script that demonstrates just that :

What the above script does is read the user details of the currently logged in user, these are basically system variables already defined and are in all capitals ( $USER, $UID and $HOME) which are echoed out. Note that $ is used to output the contents of a variable.

Here is what the output of the script is :

One more example to get the idea, this time a user-defined variable compared to the system variable earlier :

Here we have defined two variables named rosecolor and violetcolor each with values red and blue. Note that to properly output them in a sentence we use $ sign like $rosecolor and $violetcolor.

The output of above script is :

Part IV will get even more interesting , so stay tuned. 😉