Open main menu

CDOT Wiki β

Changes

Tutorial12: Shell Scripting - Part 2

120 bytes added, 15:04, 29 December 2020
INVESTIGATION 2: ADDITIONAL LOOPING STATEMENTS
# To demonstrate, issue the following set of commands:<br><br><span style="color:blue;font-weight:bold;font-family:courier;">num1=5;num2=10<br>sum=$(expr $num1+$num2)<br>echo $sum<br><br>((product=$num1*$num2))<br>echo $product</span><br><br>Let's apply this technique we just learned to correct our recently created shell script.<br><br>
# Use a text editor like vi or nano to edit the text file called '''for-6.bash''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi for-6.bash</span>)<br>If you are using the nano text editor, refer to notes on text editing in a previous week in the course schedule.<br><br>
# Change line 6 to the following:<br><span style="color:blue;font-family:courier;font-weight:bold;">((value=value+1))</span><br><br>Note: For those familiar with other programming languages, you can achieve the same results by using '''((value++))'''
# Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':wx''' followed by '''ENTER''').<br><br>
# Add execute permissions for the owner of this script and run this script.<br>What do you notice? <br><br>
13,420
edits