Category: Recent Posts
Ansible Basics – Interview Preparation
[mlw_quizmaster quiz=34]
Bash Scripting – Case Statement
Often, you’ll find yourself trying to evaluate a variable’s value, looking for a specific value within a set of possible values. In this scenario, you end up having to write a lengthy if-then-else statement, like this:
Bash Scripting – Compound Testing
The if-then statement allows you to use Boolean logic to combine tests. You can use these two Boolean operators: [ condition1 ] && [ condition2 ] [ condition1 ] || [ condition2 ] The first Boolean operation uses the AND Boolean operator to combine two conditions....
Bash Scripting – Controlling the Loop
You might be tempted to think that after you start a loop, you’re stuck until the loop finishes all its iterations. This is not true. A couple of commands help us control what happens inside of a loop: The break command The continue command Each command...
Bash Scripting – Creating a Script File
To place shell commands in a text file, first you need to use a text editor to create a file and then enter the commands into the file. When creating a shell script file, you must specify the shell you are using in the first line...
Bash Scripting – Displaying Interactive Messages
Most shell commands produce their own output, which is displayed on the console monitor where the script is running. Many times, however, you will want to add your own text messages to help the script user know what is happening within the script. You can do...
Bash Scripting – Exiting from Script
So far in our sample scripts, we terminated things pretty abruptly. When we were finished with our last command, we just ended the script. There’s a more elegant way of completing things available to us. Every command that runs in the shell uses an exit status...
Bash Scripting – Exploring more about the if-then-else Statement
In the if-then statement, you have only one option for whether a command is successful. If the command returns a non-zero exit status code, the bash shell just moves on to the next command in the script. In this situation, it would be nice to be...
Bash Scripting – How to use Nesting ifs
Sometimes, you must check for several situations in your script code. For these situations, you can nest the if-then statements: To check if a logon name is not in the /etc/passwd file and yet a directory for that user still exists, use a nested if-then statement....