How it works...

In this recipe, we wrote three scripts for a one-line if statement, for loop, and while loop. In the if example, the condition will be checked and then the output will be displayed on the screen.

In the for loop example, the echo command will be executed 10 times and Hello world will be displayed 10 times on the screen. In the while example, it will be an infinite loop. We have given a sleep of 2 seconds so that the output, 10, will be executed infinitely every 2 seconds.

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.