Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

122 bytes added, 08:45, 11 March 2021
INVESTIGATION 1: CREATING A SHELL SCRIPT
# '''Login''' to your matrix account.<br><br>
# Issue a command to '''confirm''' you are located in your '''home''' directory.<br><br>We want to create a Bash Shell script to welcome the user by their ''username''.<br>Let's first provide some useful tips in terms of selecting an appropriate name for the shell script.<br><br>
# Issue the following linux command to check if your intended shell script name<br>is already exists to be run automatically from the Bash shell:<br><span style="color:blue;font-weight:bold;font-family:courier;">which hello</span><br><br>You should notice that there is no output and therefore, this shell script name CAN be used.<br><br>[[Image:hello0.png|thumb|right|200px|Using a '''text editor''' to add Linux commands in to the '''hello''' shell script.]]
# Use a '''text editor''' like '''vi''' or '''nano''' to create the text file called '''hello'''<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 two lines in your shell script, replacing "your-username" with your actual name:<br><span style="font-family:courier;font-weight:bold;">echo<br>echo "Hello $USER"<br>echo</span><br><br>'''NOTE:''' The variable called '''USER''' is an '''environment''' variable that contains the current user's login name.<Br>In this way if you wanted to share your shell script with other users, when they run the shell script<br>it will greet by <u>their</u> username. Using ''environment variables'' makes your shell script to be more "usable" by others.<br><br>
13,420
edits

Navigation menu