Open main menu

CDOT Wiki β

Changes

Tutorial10: Shell Scripting - Part 1

2 bytes removed, 08:39, 16 March 2021
INVESTIGATION 2: SHE-BANG LINE / VARIABLES / PARAMETERS
# '''Insert''' the following line at the '''beginning''' of the '''first''' line of your hello file:<br><span style="font-family:courier;font-weight:bold;">#!/bin/bash</span><br><br>This is referred to as a '''she-bang line'''. It forces this script to be run in the '''Bash Shell'''.<br>When your Bash Shell script finishes execution, you are returned to your current shell that you are using (which in our case in Matrix, is still the Bash shell).<br><br>[[Image:hello3.png|thumb|right|275px|Changing the Bourne shell and running shell script '''with''' a '''She-bang''' line (forcing script to run in the '''Bash''' shell).]]
# '''Save''' your editing changes and '''exit''' your text editor.<br><br>
# While in the ''Bourne shell'', issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">./hello</span><br><br>You should notice that the shell name is running in the '''Bash shell''' (i.e. ''/bin/bash'').<br><br> # It is a good idea to rename your shell script to include an '''extension''' to<br>indicate that it is a '''Bash Shell''' script. <br><br>Issue the following Linux command to rename your shell script file:<br><span style="color:blue;font-weight:bold;font-family:courier;">mv hello hello.bash</span><br><br>
# Confirm that the modification work by running your Bash shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">./hello.bash</span><br><br>
# Enter the following Linux command to '''exit''' the ''Bourne shell'' and return to your ''Bash shell'':<br><span style="color:blue;font-weight:bold;font-family:courier;">exit</span><br><br>Let's use some '''ENVIRONMENT variables''' in our Bash Shell script.<br><br>
13,420
edits