bash script for list 1

bash script for list

#!/bin/bash
# Read a string with spaces using for loop
for value in I like programming
do
    echo $value
done

Here is what the above code is Doing:
1. The for loop is used to iterate over a list of items.
2. The list of items is defined after the in keyword.
3. The list of items can be a list of strings separated by spaces, a range of numbers, output of a command, an array, etc.
4. The list of items is also called word list.
5. The word list is iterated over and each word is assigned to the variable value.
6. The variable value can be used inside the loop.
7. The loop continues until all the items in the list are exhausted.

Similar Posts