Open main menu

CDOT Wiki β

Changes

Tutorial12: Shell Scripting - Part 2

541 bytes added, 09:28, 27 July 2020
Additional Loop Statements
<span style="font-family:courier">for x in $(ls)<br>do<br> &nbsp;&nbsp;&nbsp;echo “The item is: $x”<br>done</span><br><br>
 
'''while Loop Statement'''�
 
The condition/expression is evaluated, and if the condition/expression is true,<br>the code within … the block is executed. �
This repeats until the condition/expression becomes FALSE.<br>Reference: https://en.wikipedia.org/wiki/While_loop�
 
Example:��
 
<span style="font-family:courier">answer=10<br>read –p “pick a number between 1 and 10: “ guess<br>while test $guess –eq 10<br>do &nbsp;&nbsp;&nbsp;read –p “Try again: “ guess<br>done<br>echo “You are correct”</span><br><br>
===Using Startup Files===
13,420
edits