Changes

Jump to: navigation, search

Tutorial12: Shell Scripting - Part 2

2 bytes removed, 08:35, 18 March 2021
INVESTIGATION 1: ADDITIONAL LOGIC STATEMENTS
# Issue a Linux command to create a directory called '''advanced'''<br><br>
# Issue a Linux command to <u>change</u> to the '''advanced''' directory.<br><br>
# Issue a Linux command to <u>confirm</u> you are located in the '''advanced''' directory.<br><br>In a previous '''tutorial10''', you learned how to use the '''if''' control-flow statement. You will now learn to use the '''if-else''' statement<br>to take two different actions based on if the condition tests either TRUE or FALSE.<br><br>
# Use a text editor like vi or nano to create the text file called '''if-4.bash''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi if-4.bash</span>)<br><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>
# Enter the following lines in your shell script:<br><span style="font-family:courier;font-weight:bold">#!/bin/bash<br>clear<br>read -p "Enter the first number: " num1<br>read -p "Enter the second number: " num2<br>if [ $num1 -gt $num2 ]<br>then<br>&nbsp;&nbsp;&nbsp;echo "The first number is greater than the second number."<br>elif [ $num1 -lt $num2 ]<br>then<br>&nbsp;&nbsp;&nbsp;echo "The first number is less than the second number."<br>else<br>&nbsp;&nbsp;&nbsp;echo "The first number is equal to the second number."<br>fi</span><br><br>
13,420
edits

Navigation menu