Free Sample
Create a shellscript Linux Project
Solution.pdfIntroduction
A shell script is a file that contains Linux commands and special constructs. It is widely used to perform and automate administrative tasks, by combining a lengthy sequence of commands into onescript.AscriptisinterpretedandexecutedbytheLinuxshell.Therefore,anycommandthatcan beenteredontheLinuxcommandlinecanbepartofashellscript.Ashellscriptisoftencreatedas an ASCII text file by using a text editorprogram.
Inthismoduleofthecourseproject,youwillcreateandexecuteashellscriptbyexperimentingwith thestandardinput,user-definedvariables,redirection,filepermissions,andenvironmentvariables.
Procedure
-
Create a shellscript.
-
Change script filepermissions.
-
Set the PATHvariable.
-
Make the PATH variablepermanent.
Deliverable
Course Project Module 3 PowerPoint Template
-
Create a shellscript
-
In the Terminal window, enter cd ~ to return to the /home directory of your user account. Use the pwd command to verify the currentdirectory.
-
Enter nano todolist at the command prompt. Type in the script as shown in the screen capture below. Use the left, right, up, and down arrow keys to move the cursor in the nano editor. Double check the script before pressing ^x (ctrl + x), answering y to question “Save modified buffer?”, and pressing Enter to keep the same script name. Note that Linux treats upper-case and lower-case letters differently! Enter cat todolist to verify the script content.
-
Enter ls –l todolist to check the file permissions. Notice that no execute permission is set for the scriptfile.
-
Execute the script by entering bash todolist. If there are error messages displayed, go to Step 2 and double check every character includingspaces!
-
Enter 1. family. 2. work. 3. school. at the prompt and press the Enterkey.
-
Execute the script again and enter 1. school. 2. family. 3. work. at the prompt and press the Enterkey.
-
Enter cat MyToDoLists to view the two entries you enteredbefore.
-
Open theCourse Project Module 3 PowerPoint Templateand answer three questionsthere.
-
Change script filepermissions
-
In the Terminal window, enter cd ~ to return to the /home directory of your user account. Use the pwd command to verify the current directory.
-
The bash todolist command calls the bash executable/binary directly to interpret and execute the script. Another way to execute it is to make the shell script executable and declare the hashpling/shebang line (i.e., #!/bin/bash) in the script. This line specifies the pathname to the shell binary that interprets thescript.
-
Enter nano todolist to edit the script. Add #!/bin/bash as the first line of the script. In the nano editor, press ^x (ctrl + x), answer y to question “Save modified buffer?”, and press Enter to keep the same scriptname.
-
Make the script executable by entering the chmod 755 todolist command. Type ls –l todolist to verify filepermissions.
-
Enter ./todolist to execute the script by calling its name. Note that the . character represents the current directory, and ./todolist is the relative path name of the script. Enter 1. work. 2. family. 3. school. at the prompt and press the Enterkey.
-
Take a screen capture of the output in Step 5. Paste it in the Course Project Module 3 PowerPointTemplate.
-
Set the PATHvariable
-
In the Terminal window, enter cd ~ to return to the /home directory of your user account. Use the pwd command to verify the current directory.
-
PATH is an environment variable that contains a list of directories. When a command or script is called without an absolute or relative pathname, the shell searches the directories in the list for the executable file. If the file is not found, a “commandnot found” error message is displayed.
-
Enter todolist at the command prompt to observe the error message.
-
Enter echo $PATH to display the current directories in thelist.
-
Add your home directory where the todolist script is to the PATH variable by using the PATH=$PATH:/home/xxxx command. Replace xxxx with your username as in Step 1. Verify the change by entering the echo $PATHcommand.
-
Execute the script by entering todolist. Enter 1. school. 2. work. 3. family. at the prompt and press the Enterkey.
-
Take a screen capture of the output in Step 6. Paste it in the Course Project Module 3 PowerPointTemplate.
-
Make the PATH variablepermanent
-
Right click on the Ubuntu Desktop to open a NEW Terminal window. Enter cd ~ to return to the /home directory of your user account. Use thepwd
command to display the current directory.
-
Enter todolist at the command prompt to run the script. It returns the “command not found” error message. The previous change to the PATH variable does not carry over from one shell window to thenext.
-
One way of setting the PATH variable permanently is to modify the hidden .bashrc file which runs every time you open a new terminalwindow.
-
Enter ls –a .bash* to list the .bashrc file. Make a copy of it by entering the cp .bashrc .bashrc.old command, in case you need to reversechanges.
-
Enter nano .bashrc to open the .bashrc file. Add a new line export PATH=$PATH:/home/xxxx (replace xxxx with your own username as in Step 1) to the end of the file. Press ^x (ctrl + x), answer y to question “Save modified buffer?”, and press Enter to keep the same filename.
-
To active the change, use the source .bashrccommand.
-
Open another terminal window. Run the todolist script in both windows. Take a screen capture. Paste it in theCourse Project Module 3 PowerPoint Template.
Tired of the boring assignments to be submitted to colleges and universities? MyAssignmentMart.com gives you multiple reasons to trust it with your orders. We employ PhD experts handpicked from prestigious universities over the globe. We cater to quality assignment help, dissertation writing services and online essay help, covering more than 100 academic subjects. We pledge to complete your assignments on time and never compromise when it comes to deadline. Our prices for assignments are the most competitive in the market and make sure the cost suits your budget.

Get Assignment Help Now...!
Subjects We Offer
- Engineering Assignment Help
- MATLAB Assignment Help
- Mechanical Engineering Assignment Help
- Civil Engineering Assignment Help
- Computer Science Assignment Help
- Electrical Engineering Assignment Help
- Electronics Assignment Help
- Economics Assignment Help
- Management Assignment Help
- Do My Assignment
- Cheap Assignment Help
- Programming Assignment Help
- Law Assignment Help
- Assignment Provider
- Finance Assignment Help
- Python Assignment help
- Healthcare Management Assignment Help
- Computer Network Assignment Help
- History Assignment Help
- Industrial Engineering Homework Help
- IT Management Assignment Help
- Nursing Assignment Help
- Operating System Assignment Help
- Statistics Assignment Help
- Material Science Assignment Help
- Mechanical Engineering Homework Help
- University Assignment Help
- Agriculture Engineering Homework Help
- ATHE Courses Assignment Help
- Capital Budgeting Assignment Help
- BTEC Assignment Help
- HND Assignment Help
- Material Science Assignment Help
- Psychology Assignment Help
- Resit Assignment Help
- Computer Architecture Assignment Help
- Data Structure Assignment Help
- Database Assignment Help
- PHP Assignment Help