0% found this document useful (0 votes)
158 views

UNIX Shells

This document provides information about different shells available in UNIX operating systems, including the Bourne shell, C shell, TC shell, Korn shell, and Bash. It summarizes the key features of each shell and provides a comparison table of their facilities. The document also provides details on using environment variables, aliases, executing programs and scripts, and writing shell scripts for the C shell.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views

UNIX Shells

This document provides information about different shells available in UNIX operating systems, including the Bourne shell, C shell, TC shell, Korn shell, and Bash. It summarizes the key features of each shell and provides a comparison table of their facilities. The document also provides details on using environment variables, aliases, executing programs and scripts, and writing shell scripts for the C shell.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Shells

A UNIX sheII is a command-line interpreter or shell that provides a traditional user interface for
the Unix operating system and for Unix-like systems.
There are several different shells available for UNX; the most popular are described here as
follows:
O Bourne shell (sh)
O C shell (csh)
O TC shell (tcsh)
O Korn shell (ksh)
O Bourne Again SHell (bash)
Bourne Shell (sh):
O This is the original Unix shell written by Steve Bourne of Bell Labs. t is available on all
UNX systems.
O This shell does not have the interactive facilites provided by modern shells such as the C
shell and Korn shell.
O The Bourne shell does provide an easy to use language with which you can write shell
scripts.
C shell (csh)
O This shell was written at the University of California, Berkeley. t provides a C-like
language with which to write shell scripts
Korn shell (ksh)
O This shell was written by David Korn of Bell labs. t is now provided as the standard shell
on Unix systems.
O t provides all the features of the C and TC shells together with a shell programming
language similar to that of the original Bourne shell.
O t is the most efficient shell. Consider using this as your standard interactive shell.
Bourne Again SHell (bash)
O This is a public domain shell written by the Free Software Foundation under their GNU
initiative. Ultimately it is intended to be a full implementation of the EEE Posix Shell and
Tools specification. This shell is widely used within the academic commnity.
O bash provides all the interactive features of the C shell (csh) and the Korn shell (ksh). ts
programming language is compatible with the Bourne shell (sh).
O f you use the Bourne shell (sh) for shell programming consider using bash as your
complete shell environment.

Summary of shell facilities

Bourne C TC Korn BASH
________________________________________________________


command history No Yes Yes Yes Yes

command alias No Yes Yes Yes Yes

shell scripts Yes Yes Yes Yes Yes

filename completion No Yes Yes Yes Yes

command line editing No No Yes Yes Yes

job control No Yes Yes Yes Yes

________________________________________________________
* not the deIault setting Ior this shell

http://unixhelp.ed.ac.uk/shell/oview2.html

CHAPTER 2: UNIX SHELLS
back to the Computing Guide Contents

lthough the C-Shell (csh) serves as the deIault Unix shell in the MMM computing
environment, the Bourne shell (sh) and the T C-Shell (tcsh) are also available. This chapter will
cover the Iollowing basic inIormation on all three shells.
O 1he CShell
o eneral lnformaLlon
o nvlronmenL varlables
o llases
o ecuLlng rograms and ScrlpLs
o JrlLlng Shell ScrlpLs
o ecuLlng Shell ScrlpLs
O 1he 8ourne Shell
o eneral lnformaLlon
o Dslng Lhe 8ourne Shell lnLeracLlvely
o JrlLlng Shell ScrlpLs
o ecuLlng Shell ScrlpLs
O 1he 1 CSchell
o eneral lnformaLlon
o eaLures of Lhe Lcsh
o unnlng Lhe Lcsh

2.1 The C-Shell

.. Ceneral Information
ln a Dnl envlronmenL Lhe commands you enLer are eecuLed by a program called Lhe shell Jhlle
Lhere are a varleLy of shells Lhe defaulL shell on MMMs compuLers ls Lhe Cshell (csh) 1hls shell was
deslgned Lo add lnLeracLlve feaLures Lo Lhe 8ourne shell and whlle noL as robusL as Lhe 8ourne shell ls
sulLable for mosL Lasks
This section provides a quick overview oI the C-Shell. More inIormation can be Iound by using
man csh. We also highly recommend that you obtain a good csh book; many are available. We
have some copies available Ior checkout Irom the Systems library.
When a C-shell (csh) is started, it looks in two diIIerent Iiles Ior basic inIormation about the
environment. When you Iirst log onto a system, the csh reads a Iile in your home directory called
.login. From then on, whenever you start a new csh, it looks Ior a Iile in your home directory
named .cshrc. See Chapter 1 Ior more inIormation on these Iiles.
new shell is started every time you run a command or a script. ThereIore, put inIormation into
your .cshrc that should be available at all times. Generally, your .login and .cshrc Iiles should
contain environmental variables and aliases that are the same, since, in certain cases, the .login
Iile will not be executed.
.. Environment Variables
1he csh relles on a seL of varlables LhaL should be deflned ln boLh your logln and cshrc flles Lo Lell lL
abouL your envlronmenL Jhenever you sLarL a new shell Lhese varlables are passed Lo Lhe shell from
Lhe parenL 1he mosL lmporLanL varlables are
A1n
1hls ls a llsL of dlrecLorles ln whlch Lhe shell looks for commands and programs lf a program ls ln
a dlrecLory LhaL ls noL ln Lhe paLh Lhe shell wlll noL be able Lo flnd lL enerally you seL Lhls ln
your cshrc lf you change lL use Lhe rehash command Lo updaLe Lhe dlrecLory llsL
nCML
ou wlll noL need Lo seL Lhls varlable lL polnLs Lo your home dlrecLory
MANA1n
Slmllar Lo A1n ecepL lL polnLs Lo dlrecLorles ln whlch Lo look for man pages (1hls ls used on
some sysLems such as Sun)
1LkM
1he Lype of Lermlnal you are uslng 1he csh uses Lhe Lermlnal deflnlLlons glven ln Lhe Lermcap
flle lf your Lermlnal Lype ls noL deflned problems occur 1yplcal Lermlnal Lypes are vL100 or
Lerm
1LkMCA
ou do noL noL need Lo seL Lhls lL speclfles Lhe flle conLalnlng Lermlnal deflnlLlons
GkAnCA
1hls varlable deflnes Lhe ouLpuL devlce for nC raphlcs
LD_LI8kAk_A1n
1hls varlable deflnes a seL of dlrecLorles ln whlch Lo look for shareable llbrarles on Sun
sysLems JlLhouL a compleLe seL of llbrarles some programs wlll noL run
kIN1Lk
1hese commands seL Lhe defaulL prlnLer on sysLems (P lpha and Llnu sysLems
LDLS1
1hls command seLs Lhe defaulL prlnLer on SysLem v sysLems (Sl and Sun)
LASLk
Local varlable for use wlLh scrlpLs such as dup80 dup132 dupf and dotex
DISLA
lf you are uslng an x devlce you musL seL Lhls lL ls used Lo keep Lrack of Lhe dlsplay Lhe graphlcs
should be creaLed on lf you are on a console you can enLer Lhe name of Lhe machlne for
eample m|mosa00 for Lhe Sun worksLaLlon wa|nut
Dse Lhe command setenv Lo seL Lhe values of Lhese varlables
setenv LASER plum
1he command env wlll glve you a llsL of Lhe currenL varlables lndlvldual varlables can also be seen wlLh
Lhe echo command as ln Lhe followlng eample
echo $DISPLAY
.. Aliases
llases are a powerful way Lo make personal mnemonlcs for compllcaLed or ofLenused commands
ueflne an allas uslng Lhe a||as command as ln Lhe eample below 1o clear Lhe allas use Lhe una||as
command
,li,s lf 'ls -,lF |more'
ln general you should noL deflne allases LhaL are Lhe same as acLual Dnl commands especlally when
Lhe allas may requlre an lnLeracLlve response slnce problems may resulL when Lhey are used ln cerLaln
appllcaLlons or eample
,li,s rm 'rm -i'
redeflnes Lhe Dnl rm command Lo prompL Lhe user on wheLher Lo deleLe a speclflc flle now when you
use rm ln a shell scrlpL Lhe scrlpL wlll hang walLlng for a response 1o avold Lhls problem an alLernaLe
allas mlghL be
,li,s del 'rm -i'
.. Executing Programs and Scripts
ou can eecuLe complled programs and shell scrlpLs by enLerlng Lhe name of Lhe program or scrlpL aL
Lhe prompL Successful eecuLlon depends on Lhe followlng facLors
1 1he program or scrlpL musL be locaLed ln a dlrecLory LhaL ls speclfled ln your A1n varlable or
you musL lnclude Lhe paLh of Lhe program
2 ou musL have eecuLe access Lo Lhe flle and all Lhe dlrecLorles above lL (see ChapLer 3 for
lnformaLlon on Lhe |s and chmod commands)
ou can eecuLe Cshell scrlpLs wlLh Lhe Cshell source command 1hls command causes Lhe Cshell Lo
read commands from a flle
Syntax: source scriptfilename
Jhen debugglng Cshell scrlpLs lL ls besL Lo use Lhe csh command
Syntax: csh -x scriptfilename
1he x opLlon seLs Lhe echo varlable so LhaL commands are echoed Lo sLandard error (by defaulL Lhe
screen) afLer varlable subsLlLuLlons have been made and before Lhe commands are eecuLed
The C-shell has a Iacility that controls the execution oI programs and scripts. The C-shell
command, obs lists the job number, the status oI the job, and the command that generated them.
You can execute a program in background mode in one oI two ways.
Enter the program name followed by an ampersand (&)

progr,m &

Then enter jobs
The following message is displayed

( + Running progr,m

2 To suspend a running program or script, enter CTRL-Z
The following message is displayed

Stopped

To verify that the job is suspended, enter jobs, which
displays the following message

( + Stopped progr,m

Enter the C-shell command, bg to place the suspended job
in background mode
To resume the job, bring it back into the foreground with the
C-shell command, fg Again, you can verify the results with
the jobs command, which displays

( + Running progr,m
ou can also use Cshell [ob conLrol Lo LermlnaLe [obs uslng Lhe ||| command wlLh Lhe [ob number
dlsplayed by Lhe [obs command
Syntax: ill -9 %4-num-er
.. Writing Sbell Scripts
shell scrlpL ls a flle LhaL conLalns a llsL of shell commands 1he followlng secLlons lnclude Lwo eample
shell scrlpLs 1he flrsL lllusLraLes Lhe use of Lhe foreach loop consLrucL and Lhe second shows how Lo use
Lhe |fthene|se consLrucL or more lnformaLlon on wrlLlng shell scrlpLs see Lhe references aL Lhe end of
Lhls secLlon
Sample Sbell Script witb Loop Construct
1he followlng shell scrlpL coples all flles wlLh Lhe f eLenslon and glves Lhe new flles Lhe same names as
Lhe orlglnals buL wlLh sav appended aL Lhe end 1hls eample uses Lhe foreach loop consLrucL noLe
LhaL Lhe Cshell also has a wh||e loop consLrucL
bincsh
M,e , copy of e,ch file with the .f extension. New files h,ve
the s,me n,mes ,s the orgin,ls with .s,v ,ppended onto the n,me.
set files = (*.f)
fore,ch file ($files)
echo "Copying" $file "to" $file.s,v
cp $file $file.s,v
end
exit 0

Explanation of Command Lines
bincsh
Specifies the shell to be executed (in this example,the C-shell,csh)
This should be the first line in the shell script
2 M,e , copy of e,ch file with the .f extension. New files h,ve
the s,me n,mes ,s the orgin,ls with .s,v ,ppended onto the n,me.
Comments lines are preceded by a # sign, and are not executed
3 set files = (*.f)
Sets the shell variable, files to the list of files ending with
.f
4. fore,ch file ($files)
echo "Copying" $file "to" $file.s,v
cp $file $file.s,v
end
These lines comprise a C-shell fore,ch loop construct, and are
interpreted as follows: Set the shell variable file to the first
entry in the list stored in the shell variable files, execute
the commands between the fore,ch and end statements, set the
variable file to the next entry in files, and continue until file
has been set to every entry in the list stored in files
The shell commands within the loop are echo and cp The echo
command writes text to standard output (by default, the screen)
In this example, the text is a combination of quoted strings and
the contents of shell variables The cp command copies files In
this example, the first argument is the value of the shell variable
file The second argument, $file, is the value of the shell
variable file with the characters, "sav" appended to it,
"$file.s,v
. exit 0
Sets the shell variable st,tus to 0 This return status can be
used to determine the status of an executed shell script
Sample Sbell Script witb If-Tben-Else Construct
1he followlng shell scrlpL eecuLes Lhe daLe command lf yes ls enLered ln response Lo Lhe quesLlon
posed by Lhe scrlpL
bincsh
echo -n ".Do you w,nt to now tod,y's d,te? Enter yes or no:"
set ,nswer = $<
if ($,nswer == yes) then
d,te
exit
else
exit 2
endif
Explanation of Command Lines
bincsh
Specifies the shell to be executed (in this example, the C-shell, csh)
This should be the first line in the shell script
2 echo -n "Do you w,nt to now tod,y's d,te? Enter yes or no: "
Jutputs the text within the quotations to standard output (by
default, the screen)
3 set ,nswer = $<
Waits and reads characters from standard input (by default, the
terminal), and sets the shell variable ,nswer to the input string
4. if ($,nswer == yes) then
d,te
exit
else
exit 2
endif
These lines constitute the C-shell if-then-else construct Commands
in between the then and else statements (in this example, the d,te
and exit commands) are executed if the expression in the parentheses
is true The commands in between the else and endif statements (in
this example, the exit 2 command) are executed if the expression is
false
In this example, if the shell variable ,nswer is "yes", the d,te
command
is executed, the date is output to standard output, and the shell
variable st,tus is set to "" by the exit command If the shell
variable
,nswer is anything else, the exit 2 command is executed, setting the
shell
variable st,tus to the value of 2
.. Executing Sbell Scripts
1o eecuLe a shell scrlpL LhaL has been sLored ln a flle flrsL Lype chmod 7SS for chmod +x
f Lo make Lhe flle eecuLable Lhen press kL1UkN neL Lype f and press kL1UkN

n-line Information
m,n ,t
m,n b,tch
m,n csh
m,n echo
ardcopy References
The Unix C-Shell Field Guide


eLurn Lo Lop of page

2.2 The Bourne Shell

.. Ceneral Information
Llke oLher Dnl shells Lhe 8ourne shell (sh) ls a command llne lnLerpreLer an lnLerface beLween Lhe user
and Lhe sysLem LhaL can eecuLe your commands elLher lnLeracLlvely (as you Lype Lhem aL Lhe prompL)
or from a flle conLalnlng a llsL of commands called a shell scrlpL
The Bourne shell is a popular choice Ior writing shell scripts because it is quick, compact, and
contains less bugs than other shells. However, users oIten preIer other shells with a greater
choice oI command sets and Ieatures that better Iacilitate interactive use.
.. Using tbe Bourne Sbell Interactively
To begin using the Bourne shell,enter sh at the prompt
You are now in the Bourne shell, and any commands you type at the
prompt will be interpreted by this shell For information on Bourne
shell commands, see the references at the end of this section
. To exit the Bourne shell,type CTRL-d and press RETURN
.. Writing Sbell Scripts
Shell scrlpLs are Lyped dlrecLly lnLo a flle LhaL you can laLer eecuLe 1he followlng secLlon provldes
eamples of 8ourneshell scrlpLs uslng Lwo common shellscrlpL consLrucLs loops and lfLesLs or more
lnformaLlon on shellscrlpL consLrucLs and wrlLlng shell scrlpLs see Lhe references aL Lhe end of Lhls
secLlon
Sample Sbell Script witb Loop Construct
1he followlng shell scrlpL ls deslgned Lo make a copy of all flles wlLh Lhe f eLenslon and Lo glve Lhe new
flles Lhe same names as Lhe orlglnals buL wlLh sav appended aL Lhe end
binsh
M,e , copy of e,ch file with the .f extension.
New files h,ve s,me n,mes ,s origin,ls with .s,v
,ppended on the n,me.
ext=.f
files = `ls *${ext}`
for file in $files
do
echo "Copying ${file} "to" ${file}.s,v
cp ${file} ${file}.s,v
done
exit 0
Explanation of Command Lines
binsh
Specifies which shell is to be executed (here, the Bourne shell, sh)
2 M,e , copy of e,ch file with the .f extension.
New files h,ve s,me n,mes ,s origin,ls with .s,v
,ppended on the n,me.
Comments are not part of the executable script, and are preceded by
a sign
3 ext=.f
Sets the shell variable, ext to "f "
4 files = `ls *${ext}`
Executes the ls command with an argument to match all files
ending with characters specified by the ext shell variable
The results of the ls command are stored as a list in the
shell variable named files
5. for file in $files
do
echo "Copying ${file} "to" ${file}.s,v
cp ${file} ${file}.s,v
done
These lines comprise a Bourne-shell loop construct They are
interpreted as follows: Set the shell variable file to
the first entry in the list of entries stored in the shell variable
files, execute the commands between the do and
done statements, set the file variable to the next entry in
files, and continue until file has been set to every entry
in the list stored in files The first statement within the loop
(between the do and done statements) outputs text to
standard output (in this case, the screen), indicating what the
cp command will do
For example, if the variable file has been set to the entry
progr,m.f, the echo command will output: "Copying progr,m.f
to progr,m.f.s,v." The next statement will copy the file,
progr,m.f to progr,m.f.s,v
. exit 0
#eturns a status code (in this example, 0) that can be used by the
shell to pass status information on to other shell scripts
Sample Sbell Script witb If-Test Construct
1he followlng shell scrlpL eecuLes Lhe daLe command lf yes ls enLered ln response Lo Lhe quesLlon
posed by Lhe scrlpL
binsh
echo "Do you w,nt to now tod,y's d,te? Enter yes or no: \c"
re,d ,nswer
if test ${,nswer} = yes
then
d,te
exit
else
exit 2
fi
Explanation of Command Lines
binsh
Specifies which shell is to be executed (in this example, the Bourne
shell, sh)
2 echo "Do you w,nt to now tod,y's d,te? Enter yes or no: \c"
Jutputs the text within quotations to standard output (by default,
the screen)
3 re,d ,nswer
Waits and reads characters from standard input, usually terminal input
(what you type in at the keyboard)
4. if test ${,nswer} = yes
then
d,te
exit
else
exit 2
fi
These lines constitute the Bourne-shell "if" construct Commands in
between the then and else statements (in this example,
the d,te and exit commands) are executed if the
expression following the test command is true The commands in between
the else and fi statements are executed if the test
command returns false
The test command has its own syntax to test for a variety of
conditions, including string tests, numeric tests and file-type tests
This example tests a string match
The exit command returns a status code (in this case, either
or 2) that the shell can use to pass status information on to other
shell scripts
.. Executing Sbell Scripts
1o eecuLe a 8ourneshell scrlpL LhaL has been sLored ln a flle
First type chmod 755 filename or chmod +x filename
to make the file executable, then press RETURN
Next, type filename, and press RETURN
OR
2 Type sh filename and press RETURN

n-Line Information
m,n d,te
m,n exit
m,n sh
m,n test
ardcopy References
UNIX System V #elease 4 User's Guide
The Unix Programming Environment
Introducing UNIX System V


eLurn Lo Lop of page

2.3 The T C-Shell

.. Ceneral Information
1he 1 Cshell (Lcsh) ls a command lnLerpreLer LhaL ls slmllar Lo Lhe Cshell (csh) 1he synLa for wrlLlng
scrlpLs ln Lhe Lcsh ls Lhe same as for Lhe csh See secLlon 213 for eamples Dnllke Lhe csh Lhls shell ls
noL avallable on every Dnl sysLem Powever lL ls avallable on Lhe dlvlslons Sun Sl and P
worksLaLlons 1he Lcsh shell ls Lhe defaulL when you log on Lo a Llnu lnLel sysLem 1he locaLlon for Lcsh
varles beLween Lhe archlLecLures ou wlll need Lo lnclude some branchlng code ln your logln flle Lo
accomodaLe Lhls
usrloc,lbintcsh Sun, HP
usrbintcsh SGI
1he advanLage of Lhe Lcsh over Lhe csh lles ln lLs flelblllLy and numerous opLlons 1he man page
provldes deLalls abouL Lhe program 1hls documenL wlll hlghllghL some of Lhe 1 Cshells lnLeracLlve
feaLures and wlll descrlbe how Lo make Lhls shell your defaulL logln shell
.. Features of tbe tcsb
Cne feaLure of Lhe Lcsh ls commandllne edlLlng of prevlous commands uslng emacssLyle or vlsLyle
commands 1hls opLlon ls also avallable ln Lhe csh buL does noL work conslsLenLly across P Sl and
Sun worksLaLlons 1here are opLlons for movlng Lo Lhe beglnnlng and end of Lhe command llne deleLlng
characLers and words and many more of Lhe common edlLlng commands LhaL apply ln a slngle llne
seLLlng 1he defaulL edlLlng uses emacssLyle commands 1o use Lhe v| edlLlng sLyle once you are ln Lcsh
enLer
bind vi
lf you wanL Lo swlLch back Lo emacssLyle edlLlng enLer
bind em,cs
feaLure Lhe Lcsh shares wlLh Lhe csh ls lnLeracLlve command fllename and username compleLlon 1hls
feaLure can save a loL of Ledlous Lyplng 1hls command works by uslng Lhe 1A8 key (Command
compleLlon ln Lhe csh uses an LSC whlch lnLerferes wlLh commandllne edlLlng when uslng v|) or
eample Lo use Lhe feaLure for fllename compleLlon Lype Lhe command and Lhen enough characLers of
Lhe fllename Lo unlquely ldenLlfy lL 1hen press Lhe 1A8 key Lo compleLe Lhe name s an eample
suppose a dlrecLory had Lhe followlng flles ln lL
file.f fort.doc food.list
To cat Iort.doc, enter
c,t for
and Lhen press Lhe 1A8 key 1he Lcsh compleLes Lhe name
c,t fort.doc
1o cat flle1f enLer
c,t fi
and press 1A8
tber features in tcsb
O hlsLory mechanlsm LhaL provldes LlmesLamps of when Lhe commands were eecuLed
O auLomaLlc logouL opLlon
O flelble opLlons for seLLlng prompLs
O auLomaLlc perlodlc command eecuLlon
.. Running tbe tcsb
1o seL Lhe Lcsh as your logln shell
1 L Lhe end of your logln flle place Lhe followlng code
if ($MACH == sgi-sysv) then
exec usrbintcsh
else
exec usrloc,lbintcsh
endif
The branching is required as tcsh is in a diIIerent location depending on the system
architecture.
2 ln your cshrc flle place Lhe followlng llne
setenv SHELL usrloc,lbintcsh Sun P
setenv SHELL usrbintcsh Sl
1o Lry ouL Lhe Lcsh wlLhouL maklng lL your logln shell enLer
usrloc,lbintcsh Sun P
usrbintcsh Sl
aL Lhe prompL Jhen flnlshed Lype
exit
You will now leave the tcsh and return to your original shell.
http://www.mmm.ucar.edu/computing/doc/guide/ch_2.html
Shell Types:
n UN there are two major types oI shells:
1. The Bourne shell. I you are using a Bourne-type shell, the deIault prompt is the $
character.
. The C shell. I you are using a C-type shell, the deIault prompt is the character.
There are again various subcategories Ior Bourne Shell which are listed as Iollows:
O Bourne shell ( sh)
O orn shell ( ksh)
O Bourne gain shell ( bash)
O !S shell ( sh)
The diIIerent C-type shells Iollow:
O C shell ( csh)
O TENET!S C shell ( tcsh)
The original UN shell was written in the mid-1970s by Stephen R. Bourne while he was at
T&T Bell Labs in New Jersey.
The Bourne shell was the Iirst shell to appear on UN systems, thus it is reIerred to as "the
shell".
The Bourne shell is usually installed as binsh on most versions oI UN. For this reason, it is
the shell oI choice Ior writing scripts to use on several diIIerent versions oI UN.
16. Interactive Shell
Here are a Iew quick hints Ior using the UN or Linux shell interactively. !ersonally
recommend the bash shell Ior most interactive use; it is available on just about every *nix
Ilavour, and very pleasant to use as a login shell. However the root shell should always be
binsh, whether that points to bash or bourne shell.
TS_
bash has some very handy history-searching tools; the up and down arrow keys will scroll
through the history oI previous commands. More useIully, Ctrlr will do a reverse-search,
matching any part oI the command line. Hit ESC and the selected command will be pasted into
the current shell Ior you to edit as required.
I you want to repeat a command you ran beIore, and you know what characters it started with,
you can do this:
bash$ ls /tmp
(list of files in /tmp)
bash$ touch /tmp/foo
bash$ !l
ls /tmp
(list of files in /tmp, now including /tmp/foo)
s well as the arrow keys, you can use !ageUp and !ageDn to navigate to the start and end oI
the command line.
_
You can make ksh more usable by adding history commands, either in vi or emacs mode. There
are a number oI ways to do this, depending on the exact circumstances. set -o vi, ksh -o vi,
or exec ksh -o vi (where "vi" could be replaced by "emacs" iI you preIer emacs mode).
I you want to start a ksh session Irom another interactive shell, you can just call ksh like this:
csh% # oh no, it's csh!
csh% ksh
ksh$ # phew, that's better
ksh$ # do some stuff under ksh
ksh$ # then leave it back at the csh prompt:
ksh$ exit
csh%
This will start a new ksh session, which you can exit Irom and return to the previous shell.
lternatively, you could replace the csh (or whatever shell) with a ksh shell, with the exec
command:
csh% # oh no, it's csh!
csh% exec ksh
ksh$ # do some stuff under ksh
ksh$ exit

login:
The diIIerence here is that you don't get the csh session back.
The good stuII is the history:
csh% ksh
ksh$ set -o vi
ksh$ # You can now edit the history with vi-like commands,
# and use ESC-k to access the history
I you hit ESC then k, then by repeatedly hitting k you scroll backwards through the command
history. You can use vi command-mode and entry-mode commands to edit the commands, like
this:
ksh$ touch foo
ESC-k (enter vi mode, brings up the previous command)
w (skip to the next word, to go from "touch" to "foo"
cw (change word) bar (change "foo" to "bar")
ksh$ touch bar

You might also like