Question

What are the differences between a for loop and a while loop in shell scripting? Provide...

What are the differences between a for loop and a while loop in shell scripting? Provide Examples. -- UNIX/LINUX

Homework Answers

Answer #1

Both are used to iterate over the statements but the difference is for loop will have everything at one place like initilizatio and condition and increment/decrement where as while loop all three things will be at different places

we use while loop when we are not sure about the count. we will use while loop to read data from database or file

we use for loop to process the arrays and list

example:

x=0

while [ $x -lt 5 ]
do
   echo $x
   x=`expr $x + 1`
done

For Loop:

for var in 0 1 2 3
do
   echo $var
done

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

Please Like and Support me as it helps me a lot

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What are the semantic differences between a for loop and a while loop? Can you convert...
What are the semantic differences between a for loop and a while loop? Can you convert a while loop to an equivalent for loop and vice versa? If so, how? Java
Given the following output, what is the script for it? Welcome to Shell scripting Your home...
Given the following output, what is the script for it? Welcome to Shell scripting Your home directory is /home/Amal You are located now in /home/Amal/testExam Your running kernel version is Linux rehab-virtual-machine 4.13.0-37-generic #42-16.04.1-ubentu SMP … etc please give the answer in linux
What are the differences between ethics (being ethical) and the law, (following the law)? Provide examples....
What are the differences between ethics (being ethical) and the law, (following the law)? Provide examples. This is a business/management course so lets keep our discussions and examples centered on them.
Provide some examples of the differences between Piaget's and Vygotsky's approaches.
Provide some examples of the differences between Piaget's and Vygotsky's approaches.
What are the differences between current and long-term liabilities? Provide a few examples of each as...
What are the differences between current and long-term liabilities? Provide a few examples of each as applied to your chosen industry. What balance between current and long-term liabilities is best for the financial health of your company or organization?
What are the similarities and differences between 1 dimensional & 2 dimensional kinematics? Please provide 1-2...
What are the similarities and differences between 1 dimensional & 2 dimensional kinematics? Please provide 1-2 real life examples of both.
What is the purpose of an expression in a loop statement? What is the difference between...
What is the purpose of an expression in a loop statement? What is the difference between a while loop, and a do/while loop?
Why are shells important within the UNIX® environment? What elements of the shell make it important...
Why are shells important within the UNIX® environment? What elements of the shell make it important in the UNIX® environment?
Provide examples that demonstrate the differences between correlational and experimental study discussion write-ups. How are they...
Provide examples that demonstrate the differences between correlational and experimental study discussion write-ups. How are they similar/different?
Discuss with your group members the differences between Monopoly and Monopolistic Competition. Provide examples of each...
Discuss with your group members the differences between Monopoly and Monopolistic Competition. Provide examples of each type of market structure.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT