Download presentation
Presentation is loading. Please wait.
Published byMerryl Casey Modified over 9 years ago
1
EMT 2390L Lecture 8 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts
2
Outline Shell Scripts Hello World Variables Getting Input
3
Shell Scripts What is a script? o A file containing a set of commands How to write a shell script? 1.Write a script file using a text editor 2.Make the script executable 3.Specify the location of the script
4
Hello World Script File Format Features: o #! – shebang character is a sequence that indicates the name of the interpreter to be used to execute the script o # - is a comment o echo – command to display output
5
Hello World vi hello_world Copy: #!/bin/bash # This is our first script. echo 'Hello World!‘ :wq chmod 755 hello_world./hello_world
6
Scripts Location Scripts are usually located in the following directories o ~/bin - for personal use o /usr/local/bin – for anyone to use o /usr/local/sbin – for administrators to use o Custom directories added to the PATH variable Best Practices o Use correct indentation techniques for multiple commands o For commands that spam several lines, use the line-continuation sequences (backslash)
7
Variables To create a variable use a name and assignment statement and assign a value to it. Leave NO SPACES between the name and the assignment statement No datatype need to be specified, as the shell treats everything as a string o name=‘John Smith’ o age=19
8
Variable Names Conventions You may use alphanumeric characters (letter and numbers) and underscore First character must be a letter or underscore Space and special characters are not allowed Software Engineering Considerations: o Use Pascal case for variables o Use ALL CAPS for constants To read the content of a variable use $ and the variable name o i.e. for variable name use $name
9
Hello John Replace John with your name
10
Getting Input To get input you may use the read command o cp hello_world hello_who o vi hello_who o Do the following changes
11
Read Options
12
Assignments Check the class OpenLab site for new Labs o Work on the first script of Lab 6 Check Blackboard for new Quizzes Work on your Project
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.