Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

208 bytes added, 09:57, 17 February 2021
INVESTIGATION 1: CREATING A SHELL SCRIPT
# Use a '''text editor''' like '''vi''' or '''nano''' to create the text file called hello (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi hello</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 two lines in your shell script, replacing "your-username" with your actual name:<br><span style="font-family:courier;">clear<br>echo "Hello $USER"</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>
# Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':x''' followed by '''ENTER''').<br><br>Instead of issuing the '''bash''' command followed by your shell script pathname to run your shell script, let's simply run it by its filename. This is the most common method of running shell scripts.<br><br>
# Issue the following linux command to run your shell script in your current directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">./hello</span><br><br>You should notice an error indicating you don't have permissions to run the file.<br>You need to first add execute permissions prior to running the shell script.<br><br>
# Issue the following linux command to add execute permissions for your shell script:<br><span style="color:blue;font-weight:bold;font-family:courier;">chmod u+x hello</span><br><br>
13,420
edits

Navigation menu