Answers for "while loop bash"

12

while loop bash

while true;
do
	#code
done
Posted by: Guest on May-23-2020
1

shell script while loop example

#!/bin/sh
INPUT_STRING=hello
while [ "$INPUT_STRING" != "bye" ]
do
  echo "Please type something in (bye to quit)"
  read INPUT_STRING
  echo "You typed: $INPUT_STRING"
done
Posted by: Guest on May-08-2021
0

while loop shell script

#!/bin/sh

a=0

while [ $a -lt 10 ]
do
   echo $a
   a=`expr $a + 1`
done
Posted by: Guest on November-05-2020
1

shell script:while done

# The syntax is as follows:

while [ condition ]
do
   command1
   command2
   command3
done

# command1 to command3 will be executed repeatedly till the 'condition'
# is true.
# The argument for a while loop can be any boolean expression.
# Infinite loop occurs when the conditional never evaluates to false.
# Here is the while loop for a one-liner syntax:

while [ condition ]; do commands; done
while control-command; do COMMANDS; done

# For example, the following while loop will print 'welcome x times' 5 times
# on the screen:



#!/bin/bash
x=1
while [ $x -le 5 ]
do
  echo "Welcome $x times"
  x=$(( $x + 1 ))
done


# as one-liner:
x=1; while [ $x -le 5 ]; do echo "Welcome $x times" $(( x++ )); done



# Here is a sample shell code to calculate factorial using while loop:



#!/bin/bash
counter=$1
factorial=1
while [ $counter -gt 0 ]
do
   factorial=$(( $factorial * $counter ))
   counter=$(( $counter - 1 ))
done
echo $factorial



# To run just type:
$ chmod +x script.sh
$ ./script.sh 5
Posted by: Guest on July-24-2020
3

linux while loop

while true;
do
	#code
;done
Posted by: Guest on June-20-2020
0

bash while done

while CONDITION_STATEMENT; do SOME_CODE; done
Posted by: Guest on December-17-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language