Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

253 bytes added, 08:16, 11 March 2021
INVESTIGATION 2: USING VARIABLES IN SHELL SCRIPTS
=INVESTIGATION 2: USING VARIABLES IN SHELL SCRIPTS =
In this section, you will add a '''she-bang''' line at the top of your shell script to force the shell script to run in a specified shell when executed. You will also learn how to use '''variables''', '''positional ''' and '''special parameters ''' to assist you in creating adaptable make your shell scriptsmore adaptable.
# Confirm that you are located in your '''home''' directory in your Matrix account.<br><br>
# Use a text editor to edit the shell script called '''hello'''<br><br>Let's discover the importance of adding a '''she-bang''' line at the top of your shell script.<br><br>
# Add the following line to the <u>bottom</u> of the file ('''copy''' and '''paste''' to prevent ''errors''):<br><span style="font-family:courier;font-weight:bold;">echo "The current shell you are using is: $(ps -o cmd= -p $$|cut -d' ' -f1)"</span><br><br>'''NOTE:''' This command displays the '''name''' of the ''shell'' that the shell script is running in.<br>The command within <span style="font-family:courier;font-weight:bold;">$( )</span> uses a technique known as '''command substitution'''.<br><br>
# Issue the following linux command to change to the '''Bourne Shell''':<br><span style="color:blue;font-weight:bold;font-family:courier;">sh</span><br><br>You should notice your shell prompt changed that indicates that you are in a different shell.<br><br>[[Image:hello2.png|thumb|right|275px|Changing the Bourne shell and running shell script '''without''' a '''She-bang''' line.]]
13,420
edits

Navigation menu