



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Advanced Programming Tools and Techniques; Subject: Computer Science; University: Drexel University; Term: Winter 2004;
Typology: Study notes
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























Objective: To introduce students to the concept ofa shell, effective use of the shell, the shell asprogramming language, and shell scripts. We willuse the bash shell for the examples and detailsprovided.– Shell syntax and commands– history and command completion– job control– variables– programming constructs– scripts
command interpreter (bash, sh, csh,…)
-^
.bashrc, .profile
-^
PATH and shell variables
-^
metacharacters
-^
history and command completion
-^
file redirection
-^
pipes
-^
process management
-^
After reading a command, the shell may do someprocessing (see wildcards etc in the syntax description thatfollows), then it must find a program to execute thecommand.
-^
Some commands are executed directly by the shell. Othercommands are executed by separate programs. These arefound by looking in a list of directories for programs withthe appropriate name. The shell searches directories in thePATH variable. A hash table is used to make the searchfast. You can add new commands simply by adding newprograms (a program can be any executable file includingscripts – review Unix permissions) to directories in thePATH. You can modify/add directories in the PATH.
If you do not have. in your PATH, commands inyour current directory will not be found. You mayor may not want to add. to your PATH. If you donot and want to execute a command in the currentdirectory^ – ./command
-^
The PATH is searched sequentially, the firstmatching program is executed. Beware of namingyour executables test as there is another programcalled test and this may be executed when youenter^ – test
[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 $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:.:/home/jjohnson/software
[jjohnson@ws44 jjohnson]$ alias alias cd..='cd ..' alias cp='cp -i' alias d='ls' alias df='df -h -x supermount' alias du='du -h' alias kde='xinit /usr/bin/startkde' alias l='ls' alias la='ls -a' alias ll='ls -l' alias ls='ls -F --color=auto' alias lsd='ls -d */' alias md='mkdir' alias mv='mv -i' alias p='cd -' alias rd='rmdir' alias rm='rm -i' alias s='cd ..' [jjohnson@ws44 jjohnson]$ type rm rm is aliased to `rm -i'
Comments^ – # This is a comment^ – ls # list the files in the current directory
-^
Line continuation^ – echo A long ^ – > line
-^
#Command separator – you can list more than one command per line separated by ;^ – ls ; who
-^
#Pathname separator
File redirection and pipes^ – <
the next
-^
Examples^ – grep word < /usr/dict/words^ – ls > listing^ – ls >> listing^ – ls -l| wc -l
Note file redirection of standard output [stdout]does not include error messages, which go tostandard error [stderr] (when you are in a terminalsession, both stdout and stderr go to the screen;however, when you redirect stdout to a file, stderrstill goes to the screen).
-^
stdout is designated by the file descriptor 1 andstderr by 2 (standard input is 0)^ – To redirect standard error use 2>^ – ls filenothere > listing 2> error^ – ls filenothere 2>&1 > listing # both stdout and stderr
redirected to listing
jjohnson@HILBERT ~ $ find / -name me -print & [1] 1936 jjohnson@HILBERT ~ $ jobs -l [1]+ 1936 Running
find / -name me -print &
jjohnson@HILBERT ~ $ ps^ PID
PPID
PGID
WINPID TTY UID
STIME COMMAND
1608
1 1608
1608 con 1000 21:52:42 /usr/bin/bash
1936
1608
1936
1816 con 1000 09:18:03 /usr/bin/find
2036
1608
2036
1488 con 1000 09:18:07 /usr/bin/ps
jjohnson@HILBERT ~ $ kill 1936 jjohnson@HILBERT ~ $ jobs [1]+ Terminated
find / -name me -print
Control characters (hold the Ctrl key and thespecified key at the same time)^ – CTRL-C
current command – this is very handy for infinite loops,pages of output, etc.
current command
continue the command either in the foreground with fgor the background with bg
from standard input, stdin)