1 #!/bin/sh 2 3 for i in `ls` 4 do 5 if [[ "$i" == *.txt ]] 6 then 7 echo "$i is .txt file" 8 else 9 echo "$i is NOT .txt file" 10 fi 11 done
In this tutorial, we will cover the basics of the select construct in Bash. The select construct generates a menu from a list of items. It has almost the same syntax as for loop.If the user enters a number that corresponds to the number of one of the displayed items, then the value of [ITEM] is set to that item. The value of the selected item is stored in the variable REPLY. Otherwise, if the user input is empty, the prompt and the menu list are displayed again.
This tutorial explains the basics of the until loop in Bash. The until loop is used to execute a given set of commands as long as the given condition evaluates to false.
In this tutorial, we will cover the basics of for loops in Bash. We will also show you how to use the break and continue statements to alter the flow of a loop.
A Bash function is essentially a set of commands that can be called numerous times. The purpose of a function is to help you make your bash scripts more readable and to avoid writing the same repeatedly.
Loops allow you to run one or more commands multiple times until a certain condition is met. In Bash, break and continue statements allows you to control the loop execution.