DOC PREVIEW
DREXEL CS 265 - shellScripting

This preview shows page 1-2-3-4-5-6-7-8-9-10-11-12-85-86-87-88-89-90-91-92-93-94-95-96-171-172-173-174-175-176-177-178-179-180-181-182 out of 182 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 182 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 2: More UNIX, Bash Shell ScriptingProgramming Tools And EnvironmentsObjectiveObjective: To introduce students to the concept of a shell, effective use of the shell, the shell as programming language, and shell scripts. We will use the bash shell for the examples and details provided.Shell syntax and commands history and command completionjob controlvariablesprogramming constructsscriptsWhat does the shell do?In Unix, separate from the OS (change look and feel)/reads and executes commandssome handled by the shell itself (pwd, echo,…)/some are programs stored in some directory (look in directories in PATH). Start a subshell to execute theseProvides support for better interaction with the computer/OS (command history, editing, configuration)/Supports scripting (is a programming language)/Executing a CommandAfter reading a command, the shell may do some processing (see wildcards, etc in the syntax description that follows), then it must find a program to execute the command.Some commands are executed directly by the shell. Other commands are executed by separate programs. These are found by looking in a list of directories for programs with the appropriate name. The shell searches directories in the PATH variable. A hash table is used to make the search fast. You can add new commands simply by adding new programs (a program can be any executable file including scripts – review Unix permissions) to directories in the PATH. You can modify/add directories in the PATH.Finding out about Commandstype – tells you if a command is a built-in, an alias, or a program (external to the shell)/which – tells in which directory a utility is locatedhelp – displays information about built-in commands (it is a builtin itself)/info bash – a good place to read about the BASH shellExample[jjohnson@ws44 cs265]$ which echo/bin/echo[jjohnson@ws44 cs265]$ type -a echoecho is a shell builtinecho is /bin/echo[jjohnson@ws44 cs265]$ help echo # help provides information on builtin commandsecho: echo [-neE] [arg ...] Output the ARGs. If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is turned on: \a alert (bell)/ \b backspace \c suppress trailing newline \E escape character \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \\ backslash \num the character whose ASCII code is NUM (octal). You can explicitly turn off the interpretation of the above characters with the -E option.Initialisation Files•commands & variables read when shell is started•if variables are placed in system-wide init files, available to every shell•customizations must be exported to be available•commands & aliases cannot be exported so must be placed in user-specific init/etc/profile - System-Wide Initialization FileRead first by shellTasks accomplished:Sets and exports variables:PATH, TERM, PS1, etc.Displays contents of /etc/motd (msg of the day)/Sets default file creation permissions (umask)/User-specific initialisationIf the shell is a login shell, it looks for one of the following (in order)/~/.bash_profile~/.bash_login~/.profileIf a non-login interactive shell, reads~/.bashrcOther customizationsPS1 – promptPATH – add to the search pathSet shell optionsnoclobberignoreeofcommand-line editing option (vi or emacs)/See ~kschmidt/Public/.bash_profile and .bashrc for examples(Feel free to take them, as you wish)/Shell VariablesThe shell keeps track of a set of parameter names and values.Some of these parameters determine the behavior of the shell.We can access these variables:set new values for some to customize the shell.find out the value of some to help accomplish a task.Example Shell Variablessh / ksh / bashPWD current working directoryPATH list of places to look for commandsHOME home directory of userMAIL where your email is storedTERM what kind of terminal you haveHISTFILE where your command history is savedDisplaying Shell VariablesPrefix the name of a shell variable with "$" to dereferenceThe echo command will do:echo $HOMEecho $PATHYou can use these variables on any command line:ls -al $HOMESetting Shell VariablesYou can change the value of a shell variable with an assignment command (this is a shell builtin command):HOME=/etcPATH=/usr/bin:/usr/etc:/sbinNEWVAR="blah blah blah"Note the lack of spaces around the '='exportexport a variablemake it available to subshellsvalue passed inchanges made to a value in the subshell do not persist in the callerSubshell is created whenever a script or a program is runInherits parent shell's exported variablesThe PATHEach time you give the shell a command line it does the following:Checks to see if the command is a shell built-in.If not - tries to find a program whose name (the filename) is the same as the command.The PATH variable tells the shell where to look for programs (non built-in commands).echo $PATH======= [tux] - 22:43:17 =======$ echo $PATH~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gamesThe PATH is a list of ":" delimited directories.The PATH is a list and a search order.You can add stuff to your PATH by changing the shell startup file.Notes about PATHIf you do not have . in your PATH, commands in your current directory will not be found. You may or may not want to add . to your PATH. If you do not and want to execute a command in the current directory./commandThe PATH is searched sequentially, the first matching program is executed. Beware of naming your executables test as there is another program called test and this may be executed when you entertestPATH[jjohnson@ws44 software]$ echo $PATH/usr/local/FrameMaker/bin:/home/jjohnson/bin:/usr/local/gpl/mpich-1.2.4/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/openwin/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/ucb:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/UTILS/publisher/bin:/usr/bin/X11:/bin:/usr/remote/alg_soft/linda2.5.2sol2.3/bin:.[jjohnson@ws44 software]$ PATH=${PATH}:/home/jjohnson/software[jjohnson@ws44 software]$ echo


View Full Document

DREXEL CS 265 - shellScripting

Download shellScripting
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view shellScripting and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view shellScripting 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?