In: Computer Science
This is for Linux. I have not done anything on this script. Please help with simplistic commands as this is a beginner's class.
Hi,
The lines starting with '#' are comments for shell script.
For creation use the below command :
vi while.sh
For executing the script, we need to provide execution permission to the script as uder.
chmod +x while.sh
For running the script
./while.sh
Please find below :
while.sh
#!/bin/sh
#The initial value is defined
i=0
#Command prompting user to input a positive number.
#The number entered by the user is defined in a variable num.
read -p "Enter a positive number : " num
#while loop to print all the numbers between the initial variable i
to the positive number entered.
while [ $i -le $num ]
do
#Command to print all the numbers
echo $i
i=`expr $i + 1`
done
Screenshot
Output
Please like if you found it helpful.