Jump to: navigation, search
# 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 '''environment variable''' that contains the <u>current</u> user's login name. If you wanted to share your shell script with other users, when they run the shell script, they will greeted by <u>their</u> username. ''Environment variables'' make your shell script adaptable by ALL users.<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><table align="right"><tr valign="top"><td>[[Image:hello1no-execute.png|thumb|right|150px140px|Output of command from running your An '''helloerror message''' will appear when trying to run a shell script (YourUserID is your username)by name that does NOT have '''execute''' permissions.]]</td><td>[[Image:no-executepnghello1.png|thumb|right|140px150px|An Output from running your '''error messagehello''' will appear when trying to run a shell script by name that does NOT have '''execute''' permissions(YourUserID representing <u>your</u> username).]]</td></table>
# 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>

Navigation menu