Open main menu

CDOT Wiki β

Changes

Tutorial10: Shell Scripting - Part 1

775 bytes added, 11:25, 3 March 2021
INVESTIGATION 3: COMMAND SUBSTITUTION / MATH OPERATIONS
# Issue the '''chmod''' command to add execute permissions for the user for the '''command-substitution.bash''' file.<br><br>
# Issue the following to run the user-variables.bash Bash shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">./command-substitution.bash</span><br><br>Confirm that your shell script displays the correct information for your Matrix account.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week10-check-3 | more</span><br><br>If you encounter errors, make corrections and '''re-run''' the checking script until you<br>receive a congratulations message, then you can proceed.<br><br>
# Issue the following commands demonstrating using the math construct with variables:<br><span style="color:blue;font-family:courier;font-weight:bold">num1=34</span><br><span style="color:blue;font-family:courier;font-weight:bold">num2=12</span><br><span style="color:blue;font-family:courier;font-weight:bold">echo "$((num1 * num2))"</span><br><br>What did you notice?<br><br>You can create variables and assign them values in the math construction as well.<br><br>
# Issue the following commands demonstrating using the math construct with variables:<br><span style="color:blue;font-family:courier;font-weight:bold">num1=5</span><br><span style="color:blue;font-family:courier;font-weight:bold">num2=3</span><br><span style="color:blue;font-family:courier;font-weight:bold">((result = num1 ** num2))</span><br><span style="color:blue;font-family:courier;font-weight:bold">echo "The result is: $result"</span><br><br>
# xUse a text editor to create a Bash shell script called '''dog-years.bash'''<br><br># Add the following lines to the beginning of this file:<br><span style="font-family:courier;">#!/bin/bash<br>echo<br><br>dogFactor=7<br><br>read -p "Please enter your age (in years): " humanYears<br><br>((dogYears = humanYears * dogFactor))<br><br>echo "You age in dog-years is: $dogYears"</span><br># Save your editing changes and exit your text editor.<br><br># Issue the '''chmod''' command to add execute permissions for the user for the '''dog-years.bash''' file.<br><br># Issue the following to run the user-variables.bash Bash shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">./dog-years.bash</span><br><br>Enter you age to see what happens.<br><br># Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week10-check-3 | more</span><br><br>If you encounter errors, make corrections and '''re-run''' the checking script until you<br>receive a congratulations message, then you can proceed.<br><br>
=INVESTIGATION 4: USING CONTROL FLOW STATEMENTS =
13,420
edits