Normally, a Bash script will execute each line of code the moment it reaches it, then immediately move on to the next. But it is also possible to add pauses to a Bash script in order to delay it or allow the user time to respond to a prompt, etc.
scripting
Bash script: YES/NO prompt example
Interactive Bash scripts will often include a yes or no prompt in order to ask for user verification before proceeding with a set of instructions or canceling the procedure.
Bash Scripting: Read input from command line
We can make a Bash script interactive by prompting a user for input. This can be done from the command line, with our script waiting for user input in order to proceed further.
Bash script: Shebang usage and best practices
If you have looked at some of our Bash script examples across our website, or seen some others online to learn from, you may have noticed that all of the Bash scripts begin with a shebang.
Bash script: String comparison examples
The need to compare strings in a Bash script is relatively common and can be used to check for certain conditions before proceeding on to the next part of a script.
How to exit from Bash script
If you are writing a Bash script or even just executing one, an essential thing you will need to know is how to exit from a Bash script.
Bash Scripting: Conditionals
A conditional in Bash scripting is made up of two things: a conditional statement and one or more conditional operators.
Bash script: Number of arguments passed to the script
In some Bash scripts, there is an option to pass arguments to the script when you are executing it. This allows the user to specify more information in the same command used to run the script.
Bash Script: Set variable example
If you are writing a Bash script and have some information that may change during the execution of the script, or that normally changes during subsequent executions, then this should be set as a variable.
Bash Scripting: Nested if statement
An if
statement in a Bash script is the most basic way to use a conditional statement.
Bash Script: Case statement examples
If you already have some experience with writing Bash scripts, then you have probably needed to use conditional statements in the past. You may already be familiar with using if statements in a Bash script. Case statements work similarly but are more scalable and can handle many possibilities with ease.
Bash Script: Hello World Example
When getting started with a new scripting or programming language, such as Bash scripting on Linux, the first thing a user learns to create is a Hello World script.