Category: 3. Shell Loops

  • Shell Scripting until loop

    It is similar to while loop. The only difference is that until statement executes its code block while its conditional expression is false, and while statement executes its code block while its conditional expression is true. Difference between while and until Until loop always executes at least once. Loop while executes till it returns a zero value and until…

  • Shell Scripting while loop

    Linux scripting while loop is similar to C language while loop. There is a condition in while. And commands are executed till the condition is valid. Once condition becomes false, loop terminates. Syntax: Syntax of while loop is shown in the snapshot below, Example: We have shown the example of printing number in reverse order.…

  • Shell Scripting for loop

    The for loop moves through a specified list of values until the list is exhausted. 1) Syntax: Syntax of for loop using in and list of values is shown below. This for loop contains a number of variables in the list and will execute for each item in the list. For example, if there are 10 variables…

  • Shell Scripting if then elif

    A new if can be nested inside an elif. Syntax: Syntax of if then elif is shown in the snapshot below, Example if then elif: We have shown the example of choosing color. Condition: Look at the above snapshot, we have shown the script. Look at the above snapshot, on Red color it goes to if part, on Blue color it goes…

  • Shell Scripting if then else

    The if then else condition loop states that if condition meets, output goes to if part otherwise it goes to else part. The word fi represents if loop termination . Syntax: Syntax of if then else is shown in the snapshot below, Example if then else: We have shown the example of voting. If user’s age will be greater than 18…