Professional Documents
Culture Documents
Shell Programming
Shell Programming
SunOS 5.6
login: ikantz
Password:
Last login: Sat Dec 2 17:26:36 from ppp16.ath.aegean
Sun Microsystems Inc. SunOS 5.6
Generic August 1997
$ cat .profile
# @(#)local.profile 1.4 93/09/15 SMI
#
PATH=/usr/bin:/usr/ucb:/etc:. # Set path
export PATH
stty erase ^h
# Set backspace character to erase
HOME=/home/$LOGNAME
TERM=vt100
# Set the terminal definition
export TERM
umask 022
# Set the users umask value
msg n
# Refuse messages from other terminals
calendar
$ exit
File
Standard
Input
Command
Standard
Output
Command
Screen
Command
<
file cmd
>
cmd file
>>
cmd file
cmd1 | cmd2
cmd1
cmd2
-
$ ls l > temp
$ cat conf > meetings
$ cat conf >> meetings
$ cat < chap1
$ cat chap1
$ sort < file1 > file2
$ sort >file2 < file1
$ ls l | lp
$ ls l | grep khr | lp
(Shell Variables)
.
.
(.. PATH).
$
(.. $PATH).
shell prompt,
.profile, .
echo.
(Environmental Variables)
HOME
login
HOME=/users/students/
cs201999
login
PATH
shell
PATH=/bin:/home/you/b
in:
login
CDPATH
cd
CDPATH=/home/notes:/
home/you/Exercises
PS1
shell
prompt
PS1=$LOGNAME:
PS2
shell
prompt
PS2=#
>
login
(Environmental Variables)
mail
MAIL=/var/cs201999/
Mail
shell
mail
MAILFILE
mail mailx
MAILFILE=/var/mail/
$LOGNAME
mailx
SHELL
shell
SHELL=/bin/sh
editor vi
TERM
TERM=vt100
TZ
TZ=EST5EDT
$ echo hi there
hi there
$ echo $PATH
/bin:/home/you/bin:/var/add-on/bin:
$ mv notes $HOME/Stuff
$ set
$ PS1=hi there:
$ PROJ=/home/you/eork/new/urgent
$ mv file $PROJ
$ mv file PROJ
$ env
$ TERM=vt100 export TERM
-
Shell
echo.
standard output, script.
$ echo This is a test.
$ cat > show_args
This is a test.
echo $0
$ echo $PATH.
echo $1
/bin:/usr/bin:/usr/lbin:/home/becca/bin:
echo $*
$ echo `date`
#Command substitution.
^c
$ echo date
$ sh show_args hi there
echo Escape Sequencies
\b
Backspace
\t
Tab
\c
No newline
\v
Vertical tab
\f
Form feed
\\
Backslash
\n
Newline
\0n
ASCII code
\r
Return
-
Shell
read.
script .
shell.
1
$ cat > test1
echo Terminal type:\c
read TERM
export TERM
echo $TERM
^c
2
$ cat > test2
# test2 break user input into separate fields
echo Type some stuff and see what happens:
read word1 word2 word3 word4 word5
echo $word1
echo $word2 word3
echo $word4
echo $word5
^c
Shell
if
if command
then commands
fi
if $OPTION eq 1
then cat file
fi
ifelifelse
if command; then
command(s)
elif command; then
command(s)
else
command(s)
fi
Shell
case
case string
in
pattern-list)
command line
command line
;;
pattern list)
command line
command line
;;
esac
#
# del
#
echo Remove this file? \c
read OK
case $OK in
y*)
echo Removing file.
rm $1
;;
n*)
echo File will not be removed
;;
esac
Shell
for loop
for i
in list
do
commands
done
1
$ for i in 1 2 3 4 5 6 7 8 9
do
echo Hello World
done
2
#
# telno takes numbers as
# arguments, and looks up each
# name in the phone/numbers file
#
for i
do
grep $1 $HOME/phone/numbers
done
$ telno fred jim ken lynne
Shell
while
while commands1
do
commands2
done
until
until commands1
do
commands2
done
true
false
while true
do
commands
done
until false
do
commands
done