Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

30 bytes added, 11:26, 3 March 2021
INVESTIGATION 3: COMMAND SUBSTITUTION / MATH OPERATIONS
# Confirm that you are located in your '''home''' directory in your Matrix account.<br><br>
# Use a text editor to create a Bash shell script called '''command-substitution.bash'''<br><br>
# Add the following lines to the beginning of this file:<br><span style="font-family:courier;font-weight:bold;">#!/bin/bash<br>echo<br>echo "MY ACCOUNT INFORMATION:"<br>echo<br>echo "Username: $(whoami)"<br>echo<br>echo "Current Directory: $(pwd)"<br>echo<br>echo "Number of files in current directory: $(ls | wc -l)"<br>echo<br></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 '''command-substitution.bash''' file.<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>
# Use 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;font-weight:bold;">#!/bin/bash<br><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>
13,420
edits

Navigation menu