Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

6 bytes removed, 08:52, 11 March 2021
INVESTIGATION 1: CREATING A SHELL SCRIPT
# 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>
# 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 '''environmentvariable''' variable that contains the <u>current </u> user's login name. In this way, if If you wanted to share your shell script with other users, when they run the shell script<br>it , they 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.<br><br>Instead of issuing the '''bash''' command followed by your shell script pathname as an ''argument'',<br>let's simply run it by its filename. This is the most common method of running shell scripts.<br><br>[[Image:hello1.png|thumb|right|150px|Output of command from running your '''hello''' shell script (YourUserID is your username).]]
# 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>
13,420
edits

Navigation menu