Question – How do I create an infinite loop in shell script on Unix/Linux operating system? An infinite loop is used for running a set of instruction with never ending repeat. In this we create a loop which runs endlessly and keep executing the instructions until force stopped externally. Bash Infinite While Loop In...
Similar to for loop, while loop is also entry restricted loop. It means condition is checked before executing while loop. Mostly it also can do all the works which for loop can do but in uses it has own benefit of use in programming. Syntax: while [ condition ] do // programme to execute...
Command: while true;do echo “Press CTRL+C to Exit”; done Example 1: Some times we are required to execute some commands or processes continuously until stop it forcefully or conditionally. The following example of while loop will run continuously until stopped forcefully using ctrl + c. while true do echo "Press CTRL+C to Exit" done...
While Loop: while read line do echo $line done < /tmp/file.txt Note: “line” is a variable which contains a single line read from file. Example:- Some times we required to read file content line by line inside shell a script. For this example this script will read /etc/passwd file line by line and print...