home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume9
/
ksh-slides
< prev
next >
Wrap
Text File
|
1989-11-08
|
15KB
|
649 lines
Newsgroups: comp.sources.misc
organization: Math & Computer Science, Emory University, Atlanta, GA
subject: v09i003: Troff source for overhead slides on ksh
From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Reply-To: arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC})
Posting-number: Volume 9, Issue 3
Submitted-by: arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC})
Archive-name: ksh-slides
I recently gave a talk on the Korn Shell to the local Unix User's group.
I made up some overhead projector slides using troff and my friendly
laserwriter.
Figuring that perhaps the notes would be useful to a broader audience,
I am posting them here. If you use them for a talk or notes or whatever,
I'd appreciate getting credit as the original provider. Otherwise no
restrictions on this.
Arnold Robbins | Laundry increases
DOMAIN: arnold@emory.mathcs.emory.edu | exponentially in the
UUCP: gatech!emory!arnold PHONE: +1 404 727-7636 | number of children.
BITNET: arnold@emory FAX: +1 404 727-2599 | -- Miriam Hartholz
#-------------------------------- cut here ------------------------------------
#! /bin/sh
# This file was wrapped with "dummyshar". "sh" this file to extract.
# Contents: ksh-slides.tr
echo extracting 'ksh-slides.tr'
if test -f 'ksh-slides.tr' -a -z "$1"; then echo Not overwriting 'ksh-slides.tr'; else
sed 's/^X//' << \EOF > 'ksh-slides.tr'
X.ta .5i 1i 1.5i 2i 2.5i 3i 3.5i 4i 4.5i 5i 5.5i 6i 6.5i 7i 7.5i
X.ps 24 \" Yow!
X.vs 24p
X.nf
X.de CW
X.in +0.5i
X... .vs 10.5p
X.ta 16m/3u 32m/3u 48m/3u 64m/3u 80m/3u 96m/3u
X.ft CW
X.cs CW 18
X..
X.de CN
X.in -0.5i
X.ta 0.5i 1i 1.5i 2i 2.5i 3i 3.5i 4i 4.5i 5i 5.5i 6i
X... .vs
X.cs CW
X.ft R
X..
X
X.sp 6
X.ce 100
XAn Overview of the Korn Shell
X.sp 6
XArnold Robbins
X.sp 2
XEmory University
XInformation Technology Division
XTechnical Services
XSystems Support
X
X.ft CW
Xarnold@emoryu1.cc.emory.edu
Xgatech!emoryu1!arnold
X.ft R
X.ce 0
X.de fo
X.ps 15
X.ft R
X.tl 'Arnold Robbins'%'KSH Overview'
X.ft
X.ps 24
X..
X.pn 1
X.bp
X.wh -3 fo
X
X.sp 2
XOutline
X
X \(bu Brief Review of Bourne Shell Basics
X Initialization files
X Syntax
X Control Flow
X I/O Redirection
X Substitutions
X Quoting
X Pattern Matching
X Built-in Commands
X Functions
X.sp 2
X \(bu Quick Summary Korn Shell New Features
X.sp 2
X \(bu ``Detailed'' Review Korn Shell New Features
X.sp 2
X \(bu Availability Information
X.sp 2
X \(bu References
X.bp
X
X.sp 2
XBasics (System V Release 2 and later Bourne shell)
X
X \(bu Initialization files
X Login shell reads
X \f(CW/etc/profile\fP
X \f(CW$HOME/.profile\fP
X Non-login shells don't read anything
X.sp 2
X \(bu Syntax Elements
X Simple \fIcommand\fPs
X \fIPipeline\fPs: \fIcommand\fPs separated by \f(CW\(bv\fP
X \fIList\fPs: \fIpipeline\fPs
X separated by \f(CW; & && \(bv\(bv\fR
X terminated by \f(CW; &\fR
X \f(CW( \fIlist \f(CW)\fR
X \f(CW{ \fIlist \f(CW; }\fR
X
X.CW
Xvi a b c d e
Xtar -cf - . | (cd /newdir; tar -xvf -)
X{ com1; com2 ; } && { com3 ; com4 ; }
X.CN
X.bp
X
X.sp 2
XBasics (continued)
X
X \(bu Control Flow
X
X.CW
Xif \fIlist\fP
Xthen \fIlist\fP
X\fR[\fP elif \fIlist\fP # \fRrepeatable, optional\fP
Xthen \fIlist\fP \fR]\fP
X\fR[\fP else \fIlist\fP \fR]\fP # else \fRis also optional\fP
Xfi
X.sp 2
Xwhile \fIlist\fP ; do \fIlist\fP ; done
X.sp 2
Xuntil \fIlist\fP ; do \fIlist\fP ; done
X.sp 2
Xfor \fIidentifier\fP \fR[\fP in \fIword\fP ... \fR]\fP
Xdo \fIlist\fP
Xdone
X.sp 2
Xcase \fIword\fP in
X\fIpattern\fP \fR[\fP \(bv \fIpattern\fP ... \fR]\fP ) \fIlist\fP ;;
Xesac
X.CN
X.bp
X
X.sp 2
XBasics (continued)
X.sp 4
X \(bu I/O Redirection
X Basic file and pipe redirection, since Day 1
X Here Documents
X Shell operations can be redirected also
X (e.g. piping in/out of loops)
X
X.CW
X< > >> \(bv << <<-
X\fIn\fP<&\fIm\fP \fIn\fP>&\fIm\fP
X.CN
X.sp 4
X \(bu Substitutions
X Parameter (variable) substitution; e.g. \f(CW$HOME\fP
X Command substitution with \f(CW`...`\fR
X.bp
X
X.sp 2
XBasics (continued)
X.sp 4
X \(bu Quoting
X Single quotes: \f(CW'...'\fP
X \fIno\fP substitutions or escapes
X
X Double quotes: \f(CW"..."\fP
X variable and command substitutions happen
X \e \ escapes stuff
X.sp 4
X \(bu Pattern matching
X \f(CW*\fP matches anything
X \f(CW?\fP matches a single character
X \f(CW[...]\fP character classes
X \f(CW[!...]\fP negated character classes
X.bp
X
X.sp 2
XBasics (continued)
X.sp 1
X \(bu Builtin commands (most used)
X.CW
X: . break continue
Xcd echo eval exec
Xexit export read test
Xset shift times trap
Xulimit umask wait type
X.CN
X.sp 2
X \(bu Shell functions
X Arguments via \f(CW$1\fR, \f(CW$2\fR, ...
X Invoke just like any command
X Recursive function calls don't work
X No local variables
X
X.CW
Xmyfunc ()
X{
X ...
X}
X
X$ myfunc arg1 arg2 arg3
X.CN
X.bp
X
X.sp 2
XSummary: Why \fIksh\fP is so wonderful
X.sp 4
X \(bu Improved Performance
X Despite larger size, scripts often run \fImuch\fR faster
X.sp 4
X \(bu Compatibility
X Fully compatible with S5R3 Bourne Shell
X No retraining needed for \fIsh\fR users
X Eventually will comply with POSIX
X.sp 4
X \(bu Interactive use
X \fIInteractive\fP Command Line History
X Aliasing
X Start-up files
X Tilde Substitution
X Functions
X.bp
X
X.sp 2
XSummary (continued)
X.sp 4
X \(bu New features for script writing
X Functions
X The co-process
X The \f(CWselect\fP mechanism for menus
X String operations
X Parameter attributes
X Enhanced traps
X Enhanced conditionals
X.sp 4
X \(bu Check out the book
X This talk only begins to give the flavor of \fIksh\fP
X Get it and try it, you won't switch back
X.bp
X
X.sp 2
XKorn Shell New Features
X.sp 4
X \(bu Initialization files
X Login shell \(em as before
X All shells perform parameter substitution on
X the \fIvalue\fP of \f(CW$ENV\fP, and
X then read that file
X.sp 4
X \(bu Additional I/O Redirection
X Open for reading and writing
X \f(CW<> \fIfile\fR
X Override \f(CWnoclobber\fR
X \f(CW>| \fIfile\fR
X Change file descriptor of shell co-process
X \fIn\f(CW<&p \fIn\f(CW>&p\fR
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 4
X \(bu New Keywords
X \f(CW[[ ... ]]\fR New version of\ \f(CWtest\fP
X Extended conditional expressions
X No file name expansion or other word splitting
X.sp 3
X \f(CWselect\fP for providing menus
X Prompts with \f(CW$PS3\fP
X
X.CW
Xselect \fIidentifier\fP in \fIword ...\fP
Xdo
X \fIlist\fP
Xdone
X.CN
X.bp
X
X.sp
X.ce
XExample of \fIselect\fP
X
X.CW
X$ PS3="choice? "
X$ list="$(awk '{ print $2 }' /etc/fstab)"
X$ select fs in $list
X> do
X> dump 0f /dev/rmt8 $fs
X> done
X 1) /
X 2) /usr
X 3) /usr/src
X 4) /usr/src/local
X 5) /usr/aux
X 6) /usr/aux2
X 7) /var
X 8) /var/tmp
X 9) /home/psy
X10) /home/stu2
X11) /home/eucc
X12) /home/eucc2
Xchoice? 11
X\&... dumping /home/eucc
Xchoice? ^D
X$
X.CN
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 4
X \(bu Aliasing
X \f(CWalias\fP and \f(CWunalias\fP built-in commands
X tracked aliases \(em saves path searching
X exported aliases
X.sp 4
X \(bu Tilde Substitution
X \f(CW~\fR Current user's home directory
X \f(CW~\fIuser\fR \fIuser\fP's home directory
X \f(CW~+\fR Value of \f(CW$PWD\fP (current directory)
X \f(CW~\-\fR Value of \f(CW$OLDPWD\fP (previous directory)
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Command Substitution
X Use of \f(CW`...`\fP is obsoleted.
X New syntax: \f(CW$(\fIlist\fP)\fR
X Invented because of troubles mixing quotes
X and nesting quotes and backslashes
X.CW
X$((...)) -> $(let "...")
X$(< \fIfile\fP) -> $(cat \fIfile\fP)
X.CN
X
X.ft CW
X$ echo "a weird quote: $(echo '"')"
X
Xa weird quote: "
X.ft R
X.sp 2
X \(bu Parameter Substitution
X All previous mechanisms as in S5 shell.
X
X Plus new ones:
X \f(CW${#*}\fR number positional parameters
X \f(CW${#@}\fR number positional parameters
X
X \f(CW${#\fIident\fP}\fR length of \fIident\fP's value
X \f(CW${#\fIident\fP[*]}\fR number of elements in \fIident\fP
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Parameter Substitution (continued)
X \f(CW${\fIidentifier\fP#\fIpattern\fP}\fR
X \f(CW${\fIidentifier\fP##\fIpattern\fP}\fR
X Substring operation
X delete shortest/longest from \fIfront\fR
X
X \f(CW${\fIidentifier\fP%\fIpattern\fP}\fR
X \f(CW${\fIidentifier\fP%%\fIpattern\fP}\fR
X Substring operation
X delete shortest/longest from \fIend\fR
X
X.CW
X$ foo=very/long/path/name
X
X$ echo $foo ${foo#*/} ${foo##*/}
Xvery/long/path/name long/path/name name
X
X$ echo $foo ${foo%/*} ${foo%%/*}
Xvery/long/path/name very/long/path very
X.CN
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 2
X \(bu Shell Parameters
X Lots of new shell variables.
X Many others remain only for compatibility.
X Here are all that \fIksh\fP uses.
X
X.CW
XCDPATH COLUMNS EDITOR ENV
XERRNO FCEDIT FPATH HISTFILE
XHISTSIZE HOME IFS LINENO
XLINES MAIL MAILCHECK MAILPATH
XOLDPWD OPTARG OPTIND PATH
XPPID PS1 PS2 PS3
XPS4 PWD RANDOM REPLY
XSECONDS SHELL TMOUT VISUAL
X.CN
X.sp 3
X \(bu Arrays
X Variables can be arrays
X Up to 1024 elements, numbered 0 to 1023
X Array assignment via \f(CWset -A \fIname val ...\fR
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 2
X \(bu Variable Attributes
X Set via \f(CWtypeset\fR built-in
X \f(CW-L\fR left-justify
X \f(CW-R\fR right-justify
X \f(CW-Z\fR zero fill
X \f(CW-i\fR variable is an integer
X \f(CW-l\fR map all characters to lower case
X \f(CW-u\fR map all characters to upper case
X Can set maximum width of value
X Other attributes as well
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp
X \(bu File Name Generation (Pattern Matching)
X Normal patterns as in S5 shell.
X New \fIpattern-list\fPs,
X one or more patterns separated by \f(CW\(bv\fP
X \f(CW?(\fIpat-list\fP)\fR Optionally match any one pattern
X \f(CW*(\fIpat-list\fP)\fR Match zero or more of any pattern
X \f(CW+(\fIpat-list\fP)\fR Match one or more of any pattern
X \f(CW@(\fIpat-list\fP)\fR Match exactly one of the patterns
X \f(CW!(\fIpat-list\fP)\fR Match anything except a pattern
X
X\f(CW@(foo\(bvbar)\fR match \f(CWfoo\fP or \f(CWbar\fP
X\f(CW?(foo\(bvbar)\fR match \f(CWfoo\fP or \f(CWbar\fP or nothing
X\f(CW!(*.o)\fR match anything not ending in \f(CW.o\fP
X.sp 2
X \(bu Shell co-process
X \fIcommand \f(CW \(bv&\fR
X \f(CWread -p\fR
X \f(CWprint -p\fR
X \fIn\f(CW<&p \fIn\f(CW>&p\fR
X Script can be a \fIfront-end\fR to an application
X E.g., DBMS, editor
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Arithmetic Evaluation
X Integer variables (type \f(CWlong\fR in C)
X Use \f(CWtypeset -i\fP to declare them
X
X Constants are of the form [\fIbase\fP#]\fInumber\fP
X Bases from 2 to 36
X
X Use \f(CWlet\fP to do arithmetic
X All C operators supported,
X except \fP++ -- ?: ,\fR
X
X No need to use $ to get values in \f(CWlet\fP operations
X Do need to quote operands to \f(CWlet\fP
X Therefore, alternate syntax: \f(CW(( ... ))\fP
X
X Some commands automatically evaluate
X expressions; e.g., \f(CWulimit\fP
X
X.CW
X$((...)) -> $(let "...")
X.CN
X
X.ft CW
Xtypeset -i i=3 # declare i
Xlet i+=1 ; print $i # prints 4
Xlet "i *= 4" # i now 16
X((i*=2)) # i now 32
X.ft R
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Conditional Expressions
X For use in new \f(CW[[ ... ]]\fP command
X Obsoletes \f(CWtest\fR and \f(CW[ ... ]\fR
X All primitives listed under System V \fItest\fR(1)
X Additional primitives:
X.CW
X -nt -ot -ef
X -a -L -S
X -O -G
X -o \fIoption\fP
X /dev/fd/\fIn\fP
X.CN
X Additional boolean operations:
X.CW
X ! \fIexp\fP
X \fIexp\fP && \fIexp\fP
X \fIexp\fP \(bv\(bv \fIexp\fP
X.CN
X Grouping with parentheses
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 2
X \(bu Functions
X Can be recursive
X Local variables via \f(CWtypeset\fP built-in
X Can set \f(CWtrap\fPs on a per function basis
X Function tracing and debugging
X Two syntaxes:
X
X.CW
Xfunction foo # \fRpreferred\fP
X{
X ...
X}
X
Xfoo () # \fRobsoleted\fP
X{
X ...
X}
X.CN
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Enhanced built-in commands
X.CW
Xcd read
Xset trap
Xulimit
X.CN
X.sp 4
X \(bu New built-in commands
X.CW
Xalias bg fc fg
Xgetopts jobs kill let
Xprint pwd typeset unalias
Xunset whence
X.CN
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X.sp 3
X \(bu Job Control
X Patterned after 4.1BSD \fIcsh\fP (\fIcsh\fP hasn't changed)
X Trap on \f(CWCHLD\fP when a job exits
X New built-ins:
X.CW
X fg bg jobs
X.CN
X New substitutions:
X \f(CW%%\fP current job
X \f(CW%+\fP current job
X \f(CW%-\fP previous job
X \f(CW%\fInum\fR job number \fInum\fR
X \f(CW%?\fIstring\fR job name matching \fIstring\fR
X.sp 3
X \(bu History
X \f(CWHISTFILE \fRand \f(CWHISTSIZE\fR variables
X \f(CWfc\fP built-in command
X \(rh \fIvi \fRand \fIemacs \fRcommand line history editors \(lh
X These are \fIthe\fR major improvement \fIksh\fR
X offers the interactive user over other shells
X.bp
X
X.sp 2
XKorn Shell New Features (continued)
X
X \(bu Feature in \fIcsh\fP not in \fIksh\fP
X Brace expansion with \f(CW{a,b,c}\fP
X Can be compiled into \fIksh\fP, is not by default
X (Sadly, requires source, is undocumented)
X
X.CW
X% echo a{b,c,d}
Xab ac ad
X.CN
X.sp 2
X \(bu Feature only in System V Release 4
X Process Substitution
X Only available if \f(CW/dev/fd\fP is supported
X Runs commands with standard input/output
X connected to files in \f(CW/dev/fd\fP,
X said files put on the command line
X
X.CW
X some_command <(command1) >(command2)
X.CN
X
X When run, \f(CWsome_command\fP sees
X
X.CW
X some_command /dev/fd/4 /dev/fd/5
X.CN
X.bp
X
X.sp 2
XAvailability
X.sp 2
X \(bu Will be a standard part of System V Release 4
X.sp 2
X \(bu Available \fInow\fR from the AT&T Toolchest.
X (201) 522-6900, login as \f(CWguest\fP
X (201) 522-6698, voice contact
X
X $3,000 source code site license
X $20,000 binary redistribution rights
X.sp 2
X \(bu MKS \fIksh\fR for MS-DOS
X.sp 2
X \(bu Third-party suppliers for other environments
X.sp 2
X \(bu Clones and near-clones (e.g., GNU \fIbash\fR)
X.bp
X
X.sp 2
XReferences
X
X \(bu \fIksh\fR(1), the man page that comes with KSH88B.
X
X \(bu \fIThe KornShell Command and Programming
X Language\fR, Morris I. Bolsky, David G. Korn.
X Prentice-Hall, 1989. ISBN 0-13-516972-0.
EOF
chars=`wc -c < 'ksh-slides.tr'`
if test $chars != 12310; then echo 'ksh-slides.tr' is $chars characters, should be 12310 characters!; fi
fi
exit 0
--
Arnold Robbins -- Emory U. Information Technology Div. | Laundry increases
DOMAIN: arnold@emoryu1.cc.emory.edu | exponentially in the
UUCP: gatech!emoryu1!arnold PHONE: +1 404 727-7636 | number of children.
BITNET: arnold@emoryu1 FAX: +1 404 727-2599 | -- Miriam Hartholz