Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 343 Bytes

File metadata and controls

41 lines (28 loc) · 343 Bytes

Loops in Shell Scripts

Loops execute commands repeatedly.

For Loop

Example:

#!/bin/bash

for server in web1 web2 web3 do echo "Checking $server" done

Output:

Checking web1 Checking web2 Checking web3 While Loop

Example:

#!/bin/bash

count=1

while [ $count -le 5 ] do echo $count count=$((count+1)) done

Output:

1 2 3 4 5