The while loop in Shell
The while loop gives you the ability to execute a set of repetitive commands until certain conditions occur. It is often used when you need to manipulate iterative variable values.
The while loop gives you the ability to execute a set of repetitive commands until certain conditions occur. It is often used when you need to manipulate iterative variable values.
Syntax in Unix / Linux
while command do cac lenh de thuc thi neu command la true done
Here, the command is evaluated. If the result value is true, the commands are executed. If the command is false, then the statement (s) will not be executed and the program will jump to the command line after the done command.
For example in Unix / Linux
Here is a simple example that uses a while loop to display numbers from 0 to 9.
#!/bin/sh a = 0 while [ $a - lt 10 ] do echo $a a = `expr $a + 1` done
It will produce the following result:
0 1 2 3 4 5 6 7 8 9
Every time this loop executes, variable a is checked to see if it has a value of less than 10. If the value of a is less than 10, this condition has an exit status of 0. In In this case, the current value of variable a is displayed and then an increment of 1 is added.
According to Tutorialspoint
Previous post: ManPage Help in Unix
Next article: For loop in Shell
You should read it
- Loop in Unix / Linux
- For loop in Shell
- Select loop in Shell
- Until loop in Shell
- Control loop in Unix / Linux
- Network communication utilities in Unix / Linux
- What is a shell?
- Techniques cited in Unix / Linux
- Useful commands in Unix / Linux
- Instructions for installing Unix / Linux
- System log in Unix / Linux
- ManPage Help in Unix
Maybe you are interested
SpaceX's Crew Dragon spacecraft successfully assembled with the ISS station, completely automated Will NASA partner with Tesla to create the most unprecedented lunar exploration vehicle? SpaceX is about to blow up a tens of millions of dollars worth of boosters on the Atlantic WiMax gigabit speed creates 4th generation mobile network The Windows era will continue until 2023 Top 12 hottest things in the universe