background image

BA SH REFERENCE

A li

a

si

ng

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.6

A r

i

thme

ti

c Eva

l

ua

ti

on.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  8

A r

r

a

y

s .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

3

Br

a

c

e

 

Expansi

on.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  6

Bui

l

t-

In 

Comma

nds .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 1

6

Comma

nd 

Li

ne 

A r

g

uments .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  3

Comma

nd 

Substitution.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  8

Conditi

ona

Expr

e

ssi

ons .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 1

5

Contr

ol 

Comma

nds .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 1

4

Def

initi

ons .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.2

Executi

on 

Or

der.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 1

3

Fi

e

ld Spl

i

tti

ng.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  8

Func

ti

ons .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

2

H i

stor

y

 

Substitution.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  5

I

nput/

Output .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

3

I

nvoca

ti

on a

nd 

Sta

rtup 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.3

Job 

I

ds   a

nd 

Job 

Contr

ol.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 24

Options Tose

t.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 22

Options Tos hopt.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 23

Options Tote

st.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 21

Pa

tte

r

ns .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.9

Pre

-

Def

i

ned 

Va

r

ia

bl

e

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

0

Proce

ss Substitution .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  8

Prompting

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.4

Quoti

ng

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.6

Re

a

dli

ne 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

25

Re

a

dli

ne 

Dir

e

ctive

s .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 25

Re

a

dli

ne 

Ke

y

 

Bi

ndi

ng

s .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 25

Re

a

dli

ne 

Va

r

ia

bl

e

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

26

Re

str

i

c

te

dba

sh.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  2

Sig

na

ls a

nd 

Tr

a

ps .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

3

Sp

e

ci

a

l

 

Cha

r

a

c

te

r

s.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 24

Ti

l

de 

Substitution.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  6

Va

r

ia

bl

e

 

Assi

g

nment.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  9

Va

r

ia

bl

e Na

me

s .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  9

Va

r

ia

bl

e

 

Substitution .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

  7

CONTEN TS

Th

i

s re

f

erence ca

r

w a

w r

i

tten by

 

A r

nol

d Robbi

ns.

W e

th

a

nk

 

Che

t Ra

me

y

 

(

ba

sh’

ma

i

nta

i

ner

)

 

f

or h

i

s   h

e

l

p.

Speci

a

l

i

zedSy

stems   Cons ulta

nts,

 

I

nc.

(

20

6)FOR-

UNI

X/

(

20

6)

7

82-

7

7

33

FAX:

 

(

20

6)

7

82-

7

1

9

1

E-

ma

i

l

:

 

sa

l

e

s@ ssc.

com

URL:

 

h

t

t

p:

/

/

w w w.

ssc.

com

Li

nux

 

Jour

na

l

—Th

e

 

Pre

mi

e

r

 

Li

nux Ma

g

a

zine

Techni

ca

l

 

Book

s   a

nd 

CDs

SA MBA :

 

I

nteg

r

a

ting UNIX a

nd 

W i

ndow s

Sh

ell 

Tutor

ia

l

s,

 

KSH  

Ref

erence

VI

 

&

 

Emacs 

Ref

erences,

 

VI

 

Tutor

ia

l

OTHER S S C PRODUCTS:

© Copy

r

i

g

ht 1

9

9

9

 

Speci

a

l

i

zed Sy

ste

ms 

Cons ulta

nts,

 

I

nc.

,

P

.

O.

 

Box

 

55549

,

 

Se

a

ttle

,

 

W A 9

81

55-

0

549

.

A l

l

 

Ri

g

hts 

Re

se

r

ve

d.

1

Th

i

s ca

rd de

scri

bes ve

rsi

on 2.

0

2.

0

 

ofba

sh

.

Seve

ra

l ty

pef

a

c

e

s a

re used to cl

a

ri

f

y

 

the 

me

a

ni

ng

:

• Se

rif

a

 

Boldi

s   used 

f

or c

ompute

r

 

i

nput.

• Se

r

i

f

a

 

I

ta

l

i

c i

s   used to i

ndi

ca

te

 

u

se

r

 i

nput a

nd f

or

sy

nta

c

ti

c pl

a

c

e

h

ol

ders,

 

such

 

a

s va

r

i

a

bl

eorcmd.

• Se

r

i

f

a

 

Roma

i

s   used 

f

or e

x

pl

a

na

tory

 

te

x

t.

bl

a

nk

or more

 

spaces a

nd/

or

 

tab c

h

a

r

a

cte

r

s.I

n additi

on,

w or

ds a

r

e

 

te

rmi

na

ted by

 a

ny

 of

 

the f

ol

l

ow i

ng

c

h

a

r

a

c

te

r

s:

;&(

)|<>space 

tab new line

comma

nd

w ords.

l

i

st

pi

pe

l

i

ne

s.

Ca

n be 

se

pa

r

a

ted by;

,

&,

&&,

|

|a

nd optiona

l

l

y

 

be 

te

rmi

na

ted by;

,

&.

n

na

me

k

e

y

w o

r

d

ba

sh la

ng

u

a

g

e

.

Ke

y

w ords a

re sp

e

ci

a

l

 

onl

y

 

a

f

te

r

 

a;or ne

w li

ne,

 

a

f

te

r

a

noth

er k

e

y

w ord,

 

a

nd 

i

n cer

ta

i

n oth

er c

onte

x

ts.

p

a

t

ba

shpa

ttern.

 

Se

ePa

t

te

r

 

ns.

pi

pe

l

i

ne

by

 

a

 

pi

pe 

(

|

)

.

str

i

ng

su

b

st

i

tut

i

on

comma

nd l

i

ne w ith di

f

f

e

r

e

nt te

x

t,

 

e

.

g

.

,

 

r

e

pl

a

ci

ng a

va

r

ia

bl

e

  w ith  its va

l

ue. ba

sh per

f

orms  ma

ny

s ubstitutions.

 

Th

i

s ca

rd 

l

i

sts th

e

i

th

e

 

or

der

 

th

ey

 

a

re

per

f

or

med.

w o

r

d

necessa

r

y

 

i

f

 

i

t c

onta

i

ns speci

a

c

h

ar

a

c

te

r

s.

DEFI

NI

TI

ONS

I

fba

shi

i

nvok

ed a

s rba

sh,

orw ith 

the

opti

on,

 

i

t is

r

e

str

i

c

te

d.Th

e

 

f

ol

l

ow i

ng

 

a

ctions a

re not a

l

l

ow ed 

i

a

r

e

stri

c

ted 

sh

el

l

:

chang

i

ng

 

dir

e

ctory

 

w ithcd

se

tti

ng

 

or u

nse

tti

ng$

SH ELL or$

PATH

usi

ng

 

pa

th

 

na

me

f

or comma

nds th

a

t c

onta

i

n /

usi

ng

 

a

 

pa

th na

me

 

th

a

t conta

i

ns /

f

or the.

comma

nd

i

mportingf

unc

ti

ons f

r

om 

the envir

onment

pa

rsi

ng$

SH ELLOPTS a

t sta

rtup

redir

e

cti

ng

 

output 

w ith

 

a

ny

 

of>,

>|

,

<>,

>&,

&>,

or>>

usi

nge

x

e

cto run 

a

 

di

f

f

e

r

e

nt comma

nd

addi

ng

 

or dele

ti

ng bui

l

t-

i

n comma

nds 

w ithena

ble

usi

ng

to by

pa

ss 

a

 

r

e

stri

c

te

d$

PATH

usi

ngse

+

rorse

+

r

e

stri

c

te

d

Th

ese

 r

e

stri

c

ti

ons a

r

e

 i

n ef

f

ect a

f

te

r e

x

ecuting

 a

l

l

sta

r

tupf

i

l

e

s,

 

a

l

l

ow i

ng

 

th

e

 

a

uth

or

 

o

f

 

the 

sta

rtup 

f

i

l

e

f

ul

l

contr

ol

 

i

n s etti

ng up 

the 

r

e

stri

c

ted envir

onment.(

I

n

pr

a

c

ti

ce

,

 

r

e

str

i

c

ted 

sh

el

l

s a

re not used 

much

,

 

a

they

a

re di

f

f

icult to set 

up 

cor

r

e

ctly

.

)

RESTRI

CTED ba

sh

I

f

 

y

ou 

f

i

nd 

a

n er

r

or 

i

thi

s re

f

erence

 

a

nd a

r

e

 

th

e

 

f

ir

st to

repor

t it,

 

w e

 

w i

l

l

 

se

nd y

ou a

 

f

r

e

e

 

copy

 

of

 

a

ny

 

of

 

our

r

e

f

e

r

e

nce

s.

 

P

l

e

a

se w r

i

te

,

 or s e

nd e

le

ctr

oni

c ma

i

l

 to

bug

s@ssc.

com.

Er

r

or

 

Repor

ti

ng

2

ba

sh acce

pts th

e

 

one le

tter opti

ons to se

t,a

nd the

additi

ona

one

 

le

tter a

nd 

G N U-

sty

l

e

 

l

ong

 

options sh

ow n

bel

ow .

$

ba

sh[

opt

i

ons][

a

r

g

s]

ends option pr

oce

ssi

ng

ends option pr

oce

ssi

ng

cmd

e

x

e

cute cmd (

de

f

a

ult r

e

a

ds

comma

nd f

r

om f

i

l

e

 

na

med i

n

f

i

r

st 

entr

y

 

ofa

r

g

s a

nd 

f

ound vi

a

pa

th

 

s e

a

rc

h)

pr

int a

l

l

 

doubl

e quote

d

 

stri

ng

s

th

a

t a

re preceded by

 a $to

stdout.Th

i

s i

mpl

i

es

,no

comma

nds a

r

e

 

e

x

ecute

d

se

t inte

r

a

c

ti

ve 

mode

se

t r

e

str

i

c

ted 

mode

read comma

nds f

r

om

stdin

(

de

f

a

ult)

sa

me

 

a

s

,

but ou

tpu

i

n G N U

g

ettextf

orma

t

sa

me

 

a

s

di

s pl

a

y

 

a

 

h

elp 

me

ssa

g

e

 

a

nd ex

i

t

succe

ssf

ul

l

y

a

ct li

k

e

 

a

 log

i

n s h

ell

do not 

us e

 

ther

e

a

dli

nel

i

br

a

ry

to re

a

d comma

nds  w hen

i

nte

r

a

c

ti

ve

do not r

e

a

d any

  of

 

the

i

niti

a

li

za

ti

on 

f

i

l

e

s.

Se

e

I

nvoca

t

i

on And St

a

r

tup,

be

l

ow

do not r

e

a

d

˜

/

.

ba

sh

rc

i

f

i

nte

r

a

c

ti

ve

.

 

Se

e I

nvoca

t

i

on And

Sta

r

 

tup,

be

l

ow

f

ol

l

ow  the I

EEE POSIX 1

0

0

3.

2

sta

nda

r

d

f

i

l

e

use f

i

l

e i

ns te

a

d of˜

/

.

ba

sh

rc i

f

i

nte

r

a

c

ti

ve

sa

me

 

a

s

sa

me

 

a

s

pr

int ve

r

si

on i

nf

or

ma

ti

on on

stdouta

nd exit 

succe

ssf

ul

l

y

COMMA ND 

LI

NE A RGUMEN TS

Th

er

e

 

a

r

e

 

f

ive

 

w a

y

s th

a

tba

shr

uns:

 

nor

ma

l

 

i

nte

r

a

c

ti

ve,

nor

ma

l

 non-

i

nte

r

a

c

ti

ve

,

 a

s sh

,i

n POSI

X mode,

 or

i

nvok

ed vi

arshd.

1

.

 

Nor

ma

l

 

i

nte

r

a

c

ti

ve

:

 

Log

i

n s h

ell

s run comma

nds 

i

n

/

e

tc

/

profile

.The 

f

i

r

st 

of˜

/

.

ba

sh

_

profile,

˜

/

.

ba

sh

_

log

in,

a

nd ˜

/

.

profileth

a

t is found 

i

s e

x

e

cute

d.Th

i

s sta

g

e

 

i

s

sk

i

pped 

i

f

i

s   us ed.

Upon 

l

ogout,

ba

shr

uns ˜

/

.

ba

sh

_

logouti

f

 

i

t e

x

i

sts.

I

nte

r

a

c

ti

ve non-

l

og

i

n s h

el

l

s e

x

e

cute ˜

/

.

ba

sh

rc,i

f i

t

e

x

i

sts.

 

The

i

f

i

l

eopti

on 

c

h

a

ng

e

s  

the 

f

i

l

e

 

th

a

i

s

us ed.

2.

 Nor

ma

l

 non-

i

nte

r

a

c

ti

ve

:

 Non-

i

nte

r

a

c

ti

ve sh

e

l

ls   do

va

r

i

a

bl

e

,

 

comma

nd,

 

a

nd a

r

i

thme

tic substituti

on on the

va

l

ue of

$

BA SH _ENV,a

nd i

f

 

the r

e

sult na

me

s a

n

e

x

i

sti

ng

 

f

i

l

e

,

 

th

a

t f

i

l

e

 

i

s e

x

e

cuted.

I

NVOCATI

ON   A ND S TA RTUP

3

3.

 

I

nvok

ed a

s sh:I

nte

r

a

c

ti

ve l

og

i

n s h

e

l

ls re

a

d and

e

x

ecute/

e

tc

/

profilea

nd˜

/

.

profilei

f

 

th

ey

 

e

x

i

st.Th

ese

f

i

l

e

s a

re sk

i

pped i

f

i

s   us e

d.I

nte

r

a

c

ti

ve

sh

el

l

s e

x

pand $

EN V a

nd e

x

ecute

 

th

a

t

 

f

i

l

e

 

i

f

 

i

t e

x

i

sts.

Non-

i

nte

r

a

c

ti

ve sh

e

l

l

s   do not re

a

d any

 sta

rtup f

i

l

e

s.

A f

te

r

 

the 

sta

rtup 

f

i

l

e

s a

re execu

ted,

ba

shente

r

s P

OSI

X

mode.

4.

 

P

OSI

mode:

 

W hen 

sta

rte

d

 

w ith

,

i

nte

r

a

c

ti

ve

sh

el

l

s e

x

pand $

EN V a

nd execute

 

the g

i

ve

n f

i

l

e

.N o

oth

e

r sta

rtup file

s a

r

e

 

r

e

a

d

.

5.

 

I

nvok

ed vi

arshd:I

fr

un 

f

r

om rshda

nd not i

nvok

ed a

s

sh,

ba

shreads ˜

/

.

ba

sh

rc.

Th

e

option 

sk

i

ps  

thi

s

ste

p,

 

a

nd 

the

option 

c

h

a

ng

e

s  

the 

f

i

l

e

,

 

butrshd

us ua

ll

y

 

doe

s   not 

pa

ss 

th

ese

 

options on 

to the 

sh

el

l

 

i

t

i

nvok

es.

I

f$

SH ELLOPTS e

x

i

sts 

i

the envir

onment a

t sta

r

tup,

ba

shena

bl

e

the g

i

ve

n options.

I

NVOCATI

ON   A ND STA RTUP

(

c

ontinued)

W hen i

nte

r

a

c

ti

ve,ba

sh di

s pl

a

y

s the pr

ima

r

y

 a

nd

seconda

ry

 prompt str

i

ng

s,$

PS1 a

nd $

PS2.ba

sh

e

x

pands the 

f

ol

l

ow i

ng

 

e

sca

pe 

se

quences 

i

th

e

 

va

lues

of

 

th

ese

 

str

i

ng

s.

\

a

a

A SCI

I

 

BEL ch

a

r

a

c

te

r

 

(

octa

0

7

)

\

d

the da

te

 

i

W e

e

k

da

y

 

Month Da

y

’f

orma

t

\

e

a

A SCI

I

 

e

sca

pe 

c

h

a

r

a

c

te

r

 

(

octa

0

33)

\

h

th

e

 

h

ostna

me up 

to the 

f

i

r

st 

dot 

(

.

)

\

H

the 

f

ul

l

 

h

ostna

me

\

n

anew l

i

ne

\

r

aca

r

r

i

a

g

r

e

tur

n

\

s

the na

me

 

of

 

the 

sh

e

l

l

 

(

b

a

se

na

me of$

0

)

\

t

the 

time

 

i

n 24-

hour

 

H H :

MM:

SS 

f

orma

t

\

T

the 

time

 

i

n 1

2-

hour

 

H H :

MM:

SS 

f

orma

t

\

u

the use

r

s use

r

na

me

\

v

th

e

 

versi

on ofba

sh(

e

.

g

.

,

 

2.

0

2)

\

V

th

e

 

versi

on a

nd pa

tc

hl

eve

l

 

ofba

sh(

e

.

g

.

,

 

2.

0

2.

0

)

\

w

the 

cur

r

ent 

w ork

i

ng

 

dir

e

ctory

\

W

the ba

se

na

me

 

of

 

the 

cur

r

ent 

w ork

i

ng

 

dir

e

ctory

\

!

the h

i

story

 

number

 

of

 

thi

s comma

nd

\

#

the 

comma

nd number

 

o

f

 

th

i

s comma

nd

\

$

a#

i

f

 

th

e

 

ef

f

e

ctive 

UI

i

s 0

,

 

oth

er

w i

se

 

a$

\

@

the 

time

 

i

n 1

2-

h

our

 

a

m/

pm 

f

orma

t

\

\

aba

ck

sl

a

sh

\

nnn

the 

c

h

a

r

a

c

ter correspondi

ng

 

to octa

va

l

uennn

\

[

sta

r

tase

quence of

 

non-

pr

inting

 

c

h

a

r

a

c

te

r

s

\

]

end a

 

se

quence of

 

non-

pr

inting

 

c

h

a

r

a

c

te

r

s

The h

i

story

 

number

 

i

s the number

 

o

f

 

the 

comma

nd 

i

n

the h

i

story

 

li

st,

 

w h

i

ch 

ma

y

 

i

ncl

ude comma

nds r

e

store

d

f

r

om the h

i

story

 f

i

l

e

.Th

e

 comma

nd number

 

is the

number

 of

 

thi

s comma

nd sta

rti

ng

 f

r

om the f

i

rst

comma

nd 

r

un by

 

the 

cur

r

ent invoca

tion of

 

the 

sh

e

l

l

.

Th

e

 

def

a

ult 

va

l

ue ofPS1

i

.

PROMPTI

NG

4

background image

H i

story

 

e

x

pansi

on 

i

s si

mi

l

a

r to csh’

s.I

ti

s ena

bl

ed by

def

a

ult i

n  i

nte

r

a

c

ti

ve  sh

e

ll

s. H i

story

  e

x

pansi

on

h

a

ppens   be

f

ore

 

th

e

 

sh

e

l

l

 

br

e

a

k

s th

e

 

i

nput into 

w or

ds,

a

lthough qu

oti

ng

 i

s recog

niz

ed a

nd quote

d

 

te

x

t i

s

tr

e

a

ted a

s one

 

h

i

story

 

w ord’

.

H i

story

 s ubstitution i

s   pe

r

f

ormed on hi

story eve

nts,

w hi

ch cons i

st 

of

 

a

n eve

nt 

de

si

g

na

tor(

w hi

ch pr

e

vi

ous 

li

ne

to sta

rtw ith)

,

 

aw ord de

si

g

na

tor(

w h

i

ch 

w ord from 

th

a

t

l

i

ne to use

,

 

sta

rti

ng

 w ith

 

zero),

 

a

nd one or more

optiona

l modi

f

i

e

r

s (

w hi

ch pa

r

ts of

 

the 

w ords to use

)

.

Col

ons sepa

r

a

te

 

the 

thr

e

e

 

p

a

r

ts,

 

a

lthough the 

col

on

betw een th

e

 

e

vent desi

g

na

tor a

nd w ord de

si

g

na

tor

ma

y

 

be omitted 

w hen 

the 

w ord de

si

g

na

tor beg

i

ns  

w ith

ˆ

,

$

,

*

,,

or%.

Ea

ch 

modi

f

ie

r

 

i

s sepa

r

a

te

d

 

f

r

om 

th

e

 

ne

x

t

one 

w ith

 

a

 

col

on.

Th

ehistc

h

a

rs va

r

ia

bl

e

 

speci

f

ie

the

sta

r

t-

of

-

hi

storya

nd qui

ck

 

substitution 

c

h

a

r

a

c

te

r

s,

 

a

nd

a

lso 

the 

comment c

h

a

r

a

c

te

r

 

th

a

t i

ndi

ca

te

s th

a

t the 

r

e

st

of

 

a

 

l

i

ne 

i

s a comment.The pr

e

vi

ous comma

nd 

i

s the

def

a

ult 

eve

nt if

 

no eve

nt 

desi

g

na

tor 

i

s suppl

i

ed.

Th

e

 

e

vent 

de

si

g

na

tors a

r

e

:

!

sta

r

tahi

story

 

s ubstituti

on

!

n

comma

nd 

li

nen

n

cur

r

ent li

ne 

mi

nus n (

n pr

e

vi

ous)

!

!

the pr

e

vi

ous comma

nd

!

str

most r

ece

nt c

omma

nd 

l

i

ne 

sta

rti

ng

 

w ith

str

!

?str

[

?]

most r

ece

nt c

omma

nd 

l

i

ne 

conta

i

ni

ngstr

!

#

the entir

e comma

nd 

l

i

ne 

ty

ped 

so 

f

a

r

ˆ

ol

d

ˆ

ne

w

ˆ

qui

ck

 

substitution:

 

r

epeat

 

la

st comma

nd

chang

i

ngol

dtone

w

The 

w ord de

si

g

na

tors a

r

e

:

0

the 

zero’

th 

w ord (

comma

nd na

me

)

n

w ordn

ˆ

the 

f

i

r

st 

a

rg

ument,

 

i

.

e

.

,

 

w or

d one

$

the 

la

st a

rg

ument

%

the w ord ma

tched by

 the most r

ece

nt

!

?str

?se

a

rch

xy

w or

ds xth

rou

g

hy

. i

s sh

or

tf

or

*

w ords 1

 

th

r

o

u

g

h

 

th

e

 

l

a

st (

l

i

k

e

)

n

*

w or

ds nthrou

g

h

 

th

e

 

l

a

st (

l

i

k

en

)

n

w or

ds nthrou

g

h

 

th

e

 

ne

x

t to 

l

a

st

The 

modi

f

iers a

r

e

:

e

re

move

 

a

l

l

 

but the 

s uf

f

i

x

 

of

 

a

 

f

i

l

e

na

me

g

ma

k

e

 c

h

a

ng

e

s gl

oba

l

l

y

, us e

 w ith s

modi

f

i

er

,

be

l

ow

h

re

move

 the l

a

st pa

r

t of a f

i

l

e

na

me,

l

e

a

vi

ng

 

the 

h

e

a

d’

p

pr

int the 

comma

nd but 

do not e

x

e

cute

 

i

t

q

quote

 

th

e

 

g

e

nera

te

d

 

te

x

t

r

re

move

 

the 

l

a

st suf

f

i

x

 

of

 

a

 

f

i

l

e

na

me

s/

ol

d

/

ne

w

/ s ubstitutene

w f

orol

d i

the 

te

x

t.A ny

del

i

mite

r

 ma

y

 be use

d.A n & i

n the

repl

a

c

e

ment 

me

a

ns th

e

 

va

lue ofol

d.

W ith

e

mptyol

d,

use

 

l

a

stol

d,

orthe 

most r

ece

nt

!

?str

?se

a

rc

i

f

 

th

er

e

 

w a

no pr

e

vi

ous ol

d

t

re

move

 

a

l

l

 

but the 

l

a

st 

pa

r

tofaf

i

l

e

na

me,

l

e

a

vi

ng

 

the 

ta

i

l

x

quote

 

th

e

 

g

e

ne

r

a

te

d

 

te

x

t,

 

but bre

a

k

 

i

nto

w ords a

tbl

a

nk

s a

nd ne

w l

i

ne

&

repea

t th

e

 

l

a

st substitution

H I

STORY SUBSTI

TUTI

ON

5

\

c

quote

 

si

ng

l

e

 

ch

a

r

a

c

te

rc

`

.

.

.

`

ol

d s ty

l

e comma

nd 

s ubstitution

"

.

.

.

"

te

x

t tr

e

a

te

d

 

a

s a

 

si

ng

l

e

 

a

r

g

ument,

 

doubl

e

quote

re

move

d;

 

v

a

ri

a

bl

e

,

 

c

omma

nd and

a

rithme

ti

c substitutions   per

f

ormed;

use\to quote$

,

\

,

`

,

a

nd"

$

"

.

.

.

"

l

i

k

e"

.

.

.

"

,

but loca

le

 

tra

nsla

ti

on done

´

.

.

.

´

te

x

t tr

e

a

te

d

 

a

s a

 

si

ng

l

e

 

a

r

g

ument,

 

si

ng

l

e

quote

s re

move

d;

 

te

x

betw e

e

n quotes

l

e

f

t

 

a

l

one,

 

c

a

nnot 

i

nclude´

$

´

.

.

.

´

te

x

t tr

e

a

te

d

 

a

s a

 

si

ng

l

e

 

a

r

g

ument,

$

a

nd

si

ng

l

e quote

s re

move

d;

 

no 

s ubstitutions

per

f

ormed;

 

A N SI

 

a

nd additi

ona

l

e

sca

pe 

se

quenc

e

proce

ssed:

\

a

a

l

e

r

t(

be

l

l

)

\

v

vertic

a

lta

b

\

b

ba

ck

spa

ce

\

ddd

octa

l

 

va

lueddd

\

f

f

or

f

e

e

d

\

xh

h

h

h

e

x

 

va

l

ueh

h

h

\

n

new l

i

ne

\

\

ba

ck

sla

sh

\

r

ca

r

r

i

a

g

e

 

r

e

tur

n

\

e

e

sca

pe,

 

not i

n A N SI

 

C

\

t

h

oriz

onta

l ta

b

QUOTI

NG

a

li

a

s na

me

=va

l

ue.

.

.

A l

i

a

se

s a

r

e

 

e

x

panded 

w hen a

 comma

nd 

i

s re

a

d,

 not

w h

e

n e

x

ecute

d.A li

a

s na

me

s ca

n conta

i

n a

ny

 non-

speci

a

l

 

c

h

a

r

a

c

te

r,

not j

us t a

lpha

nume

ri

cs,

 

e

x

ce

pt f

or=.

A li

a

s e

x

pansi

on 

i

s   done on 

the 

f

irstw o

r

dof

 

a comma

nd.

I

f

 

the 

l

a

st c

h

a

r

a

c

ter of th

e

 

r

e

pl

a

c

e

ment te

x

t is 

abl

a

nk

,

then 

th

e

 

nex

w ord 

i

the 

comma

nd 

l

i

ne 

i

s ch

eck

e

f

or

a

li

a

s e

x

pansi

on.

A li

a

se

s ca

n even be use

to rede

f

i

ne

sh

el

l

 

k

ey

w or

ds ,

 

but 

not in POSI

mode.

ALI

A SI

NG

Br

a

c

e

 

e

x

p

a

nsi

on i

s si

mi

l

a

r to csh

s.A w ord must

conta

i

n a

t le

a

st 

one unquote

d

 

le

f

t

 

br

a

c

e

 

a

nd comma

 

to

be expanded.ba

sh expands the comma

-

se

pa

r

a

te

d

ite

ms i

n or

der

,the resu

lt i

s   not sorte

d

.

 

Bra

c

e

e

x

pansi

ons 

ma

y

 

be nested.

 

For

 

e

x

a

mpl

e

:

$

mk

dir /

usr/

{

gnu,

loca

l}/

{sr

c

,

bin,

lib}

BRA CE EXP

A NSI

ON

˜

s ubstitute$

H OME

˜

u

se

r

s ubstituteu

se

r

s   h

ome dir

e

ctory

˜

+

s ubstitute$

PW D

s ubstitute$

OLD PW D

˜

n

s ubstitute$

{

DI

RSTA CK[

n

]

}.A lea

di

ng+

or

i

s a

ll

ow ed:

 ne

g

a

tive va

l

ues count

f

r

om 

the end of

 

the 

sta

c

k

Ti

lde 

s ubstitution h

a

ppens a

f

te

r

 

a

li

a

s e

x

pansi

on.I

i

s

done f

or w ords th

a

t beg

i

n w ith ˜a

nd f

or

 va

r

ia

bl

e

a

ssi

g

nment.

I

n va

r

ia

bl

e

 

a

ssi

g

nments,

 

it i

s a

lso 

done

 

af

te

r

 

a:i

the

va

l

ue.

 

Ti

l

de s ubstitution i

s   done

 

a

s   pa

r

t of w ord

e

x

pansi

on.

 

Th

i

me

a

ns  

f

or$

{

na

me

 

op 

w o

r

d

},

w o

r

dw i

l

l

 

be

check

ed 

f

or ti

l

de 

s ubstitution,

 

but onl

y

 

i

f

 

th

e

 

oper

a

ti

on

requ

ir

e

th

e

 

va

lue of

 

the 

r

ig

ht-

h

a

nd 

si

de.

TI

LDE 

SUBSTI

TUTI

ON

6

$

na

me

reference

 

to sh

e

l

l

 

va

r

ia

bl

ena

me

$

{

na

me

}

us e

 

br

a

c

e

s to deli

mit 

sh

el

l

 

va

r

ia

bl

ena

me

$

{

na

me w o

r

d

}

us e va

r

ia

bl

ena

mei

f

 

se

t,

 

e

l

se

 

usew o

r

d

$

{

na

me

=w o

r

d

}

a

s a

bove but a

lso se

tna

metow o

r

d

$

{

na

me

?w o

r

d

}

usena

mei

f

 

se

t,

 

oth

e

rw i

se

 

pr

intw o

r

da

nd

e

x

it (

inte

r

a

c

ti

ve 

sh

ell

s   do not e

x

it)

$

{

na

me

+w o

r

d

}

usew o

r

di

fna

mei

s se

t,

 

oth

e

rw i

se

 

use

nothi

ng

$

{

na

me

[

n

]}

e

l

e

mentni

n a

r

r

a

yna

me

$

{

#

na

me

}

l

eng

th

 

of

 

sh

el

l

 

va

r

ia

bl

ena

me

$

{

#

na

me

[

*

]

 

}

number of e

le

ments 

i

n a

r

r

a

yna

me

$

{

#

na

me

[

@]

 

}

number of e

le

ments 

i

n a

r

r

a

yna

me

$

{

na

me

#

p

a

t

}

re

move

 

sh

or

te

st le

a

di

ng

 

s ubstr

i

ng

ofna

meth

a

ma

tch

e

s p

a

t

$

{

na

me

#

#

p

a

t

} re

move

 

l

ong

est 

l

e

a

di

ng

 

s ubstr

i

ng

ofna

meth

a

ma

tch

e

s p

a

t

$

{

na

me

%p

a

t

} re

move

 

sh

or

te

st tr

a

i

l

i

ng

 

s ubstr

i

ng

ofna

meth

a

ma

tch

e

s p

a

t

$

{

na

me

%%p

a

t

}

re

move

 

l

ong

est tr

a

i

l

i

ng

 

s ubstr

i

ng

ofna

meth

a

ma

tch

e

s p

a

t

$

{

na

me

:

sta

r

t

}

$

{

na

me

:

sta

r

t

:

l

e

ng

th

}

l

e

ng

thc

h

a

r

a

c

te

r

s ofna

mesta

r

tinga

t

sta

r

t(

counting

 

f

r

om 0

)

;

 

us e

 

r

e

st of

va

l

ue 

i

f

 

nol

e

ng

th

.

N e

g

a

tivesta

r

t

counts f

r

om 

the end.

I

fna

mei

s *or@

or a

n a

rra

y

 

i

nde

x

ed by*or@,

sta

r

t

a

ndl

e

ng

thi

ndi

ca

te

 

th

e

 

a

r

r

a

y

 

i

nde

x

 

a

nd

count 

of

 

e

l

e

ments.

sta

r

ta

ndl

e

ng

thc

a

n

be a

r

i

thme

ti

c

 

e

x

pr

e

ssi

ons

$

{

na

me

/

pa

tte

r

n

/

str

i

ng

}

va

l

ue ofna

mew ith

 

f

ir

st 

ma

tch ofpa

tte

r

n

repl

ace

w ithstr

i

ng

$

{

na

me

/

pa

tte

r

n

}

va

l

ue ofna

mew ith

 

f

ir

st 

ma

tch ofpa

tte

r

n

del

e

te

d

$

{

na

me

/

/

pa

tte

r

n

/

str

i

ng

}

va

l

ue ofna

mew ith

 

e

ver

y

 

ma

tch of

pa

tte

r

n r

epl

ace

w ithstr

i

ng

$

{

na

me

/

#

pa

tte

r

n

/

str

i

ng

}

va

l

ue ofna

mew ith

 

ma

tch ofpa

tte

r

n

repl

ace

w ithstr

i

ng

;ma

tch 

mus t occur

a

beg

i

nni

ng

$

{

na

me

/

%pa

tte

r

n

/

str

i

ng

}

va

l

ue ofna

mew ith

 

ma

tch ofpa

tte

r

n

repl

ace

w ithstr

i

ng

;ma

tc

h

 

occurs 

a

t e

nd

Note

:f

or ,=,?,a

nd +

,usi

ngna

me

:i

nste

a

d ofna

me

te

sts 

w h

etherna

mei

s se

t a

nd non-

NULL;

 

usi

ngna

me

te

sts onl

y

 

w h

etherna

mei

s se

t.

For#

,

#

#

,

%,

%%,

/

,

/

/

,

/

#

,

a

nd/

%,

w hen na

mei

s *or@

or a

n a

rra

y

 i

nde

x

ed by * or @,the s ubstr

i

ng

 or

s ubstitution oper

a

ti

on 

i

s a

ppl

i

ed 

to e

a

c

h

 

e

l

ement.

VA RI

A BLE SUBSTI

TUTI

ON

7

A r

i

thme

ti

c eva

l

ua

tion i

s   done w ith the let bui

l

t-

i

n

comma

nd,

 

the (

(

.

.

.

)

) comma

nd and  the $

(

(

.

.

.

)

)

e

x

pansi

on 

f

or produci

ng

 

the 

r

e

sult 

of

 

a

n e

x

pr

e

ssi

on.

A l

l

 

a

rithme

ti

c use

s longi

nte

g

e

rs.

 

Use

to g

e

t

i

nte

g

e

r va

ri

a

bl

e

s.I

nte

g

e

r consta

nts 

l

ook

 

li

k

e

 

[

ba

se

#

]

n

w h

er

eba

sei

s a

 

deci

ma

number

 

betw e

e

tw o a

nd 

64,

a

ndn i

i

th

a

ba

se

.

The di

g

its a

r

e0

-

9

,

a

-

z,

A -

Z,

_a

nd

@.

A l

e

a

di

ng0or0

xdenote octa

l

 

or h

e

x

a

deci

ma

l

.

The 

f

oll

ow i

ng

 oper

a

tors b

a

sed on C,

 w ith the 

sa

me

precedence and associ

a

ti

vity

,

a

re ava

i

la

bl

e.

una

ry

 

pl

us   a

nd 

mi

nus

l

og

i

ca

a

nd bitw i

se

 

ne

g

a

tion

*

*

e

x

ponentia

ti

on 

(

not i

n C)

*/

%

multi

pl

y

,

di

vi

de,

 

modul

us

additi

on,

 

subtr

a

ction

<< >>

l

e

f

s h

i

f

t,

 

r

i

g

ht shi

f

t

< <= > >=

compa

r

isons

== !

=

equa

ls,

 

not equa

l

s

&

bitw i

se

 

A N D

ˆ

bitw i

se

 

XOR

|

bitw i

se

 

OR

&&

l

og

i

ca

A N D,

 

sh

or

tcir

cui

t

|

|

l

og

i

ca

OR,

 

sh

or

tcir

cui

t

?:

i

n-

l

i

ne 

conditi

ona

l

a

ssi

g

nment ope

r

a

tors

I

nsi

delet,

(

(

.

.

.

)

)

,

a

nd$

(

(

.

.

.

)

)

,

va

r

ia

bl

e

 

na

me

do not 

need

a$

to g

e

t th

e

i

r

 

va

l

ues.

A RI

TH METI

C EVALUATI

ON

$

(

comma

nd

) new  

f

or

m

`

comma

nd

`

ol

f

or

m

Run comma

nd,s ubstitute

 

the r

e

sults a

s a

r

g

uments.

Tra

i

l

i

ng

 

ne

w li

nes a

re re

move

d.

 Cha

r

a

c

te

r

s i

n $

IFS

se

pa

r

a

te

 

w or

ds (

se

eFi

el

d Spl

i

t

t

i

ng

)

.

 Th

enew  

f

orm 

i

s

pr

e

f

e

r

r

e

d

 

f

o

r

 

simpler quoti

ng

 

r

ul

e

s.

$

(

(

e

x

pr

e

ssi

on

)

)a

rithme

ti

c substitution

Th

ee

x

pr

e

ssi

on i

s eva

lua

ted,

 

a

nd th

e

 

result is   used a

s   a

n

a

rg

ument to th

e

 

curre

nt comma

nd.

COMMA ND SUBSTI

TUTI

ON

cmd

<(

l

i

st1

)>(

l

i

st2

)

Runs l

i

st1a

nd l

i

st2 a

sy

nchronous ly

,w ith stdin a

nd

stdout r

e

specti

ve

l

y

 

conne

cte

d

 

vi

a

 

pi

pes usi

ng

 

f

i

f

os or

f

i

l

e

i

n /

dev/

f

d.

Th

ese

 

f

i

l

e na

me

become

 

a

r

g

uments to

cmd,

w hi

c

h

 

e

x

pects to re

a

d

 

its f

i

r

st 

a

rg

ument a

nd 

w r

i

te

its second.

 

Th

i

s onl

y

 

w ork

i

f

 

y

ou h

a

ve/

dev/

f

do

r

 

f

ifos.

PROCESS SUBSTI

TUTI

ON

Quoted  te

x

t become

s one  w ord. Oth

er

w i

se

,

occur

r

ences of

 

a

ny

 

c

h

a

r

a

c

te

r

 

i

n $

IFS se

pa

r

a

te

 

w ords.

Multi

pl

e

 

w hite

spa

c

e

 

ch

a

r

a

c

te

r

s th

a

t a

r

e

 

i

n $

IFS do not

del

i

mit e

mpty

 

w ords,

 w hi

l

e

 multi

pl

e non-

w hite

spa

ce

c

h

a

r

a

cte

r

s do.W hen $

IFS i

s   not the def

a

ult va

lue,

se

quences of

 

le

a

di

ng

 a

nd tr

a

i

l

i

ng $

IFS w hite

spa

ce

c

h

a

r

a

c

te

r

s a

re re

moved,

 a

nd pr

inta

bl

e ch

a

r

a

c

te

r

s i

n

$

IFS

s ur

r

ounded by

  a

dj

ace

nt $

IFS

w hite

spa

ce

c

h

a

r

a

cte

r

deli

mit f

i

e

lds.I

f$

IFS i

s NULL,ba

shdoes

not 

do 

f

i

e

l

d s pli

tti

ng

.

FI

ELD SPLI

TTI

NG

8

background image

?

ma

tch

 

si

ng

l

e

 

ch

a

r

a

c

te

r

 

i

f

i

l

ena

me

*

ma

tc

h

 

0

 

or 

more

 

c

h

a

r

a

c

te

r

i

f

i

l

e

na

me

[

c

h

a

r

s

]

ma

tch

 

a

ny

 

ofc

h

a

r

s

(

pa

i

r

 

se

pa

r

a

te

d

 

by

 

a ma

tch

e

s a

 

rang

e

)

[

!

c

h

a

r

s

]

ma

tch

 

a

ny

 

e

x

ce

ptc

h

a

r

s

[

ˆ

c

h

a

r

s

]

ma

tch

 

a

ny

 

e

x

ce

ptc

h

a

r

s

I

f

 

the ex

tg

lob option to s hopt i

s se

t,

 

the f

ol

l

ow i

ng

e

x

te

nded 

ma

tch

i

ng

 

f

a

ci

l

i

tie

ma

y

 

be use

d.

?(

pa

t

-

l

i

st

)

optiona

l

l

y

 

ma

tc

h

 

a

ny

 

of

 

the pa

tterns

*

(

pa

t

-

l

i

st

)

ma

tc

h

 

0

 

or 

more

 

of

 

a

ny

 

of

 

the pa

tterns

+

(

pa

t

-

l

i

st

)

ma

tc

h

 

1

 

or 

more

 

of

 

a

ny

 

of

 

the pa

tterns

@(

pa

t

-

l

i

st

)

ma

tch

 

e

x

a

ctly

 

1

 

of

 

a

ny

 

of

 

the pa

tterns

!

(

pa

t

-

l

i

st

)

ma

tch

 

a

ny

thi

ng but a

ny

 

of

 

the pa

tterns

pa

t

-

l

i

sti

s a

 

l

i

st 

of

 

one or

 

more

 

p

a

tterns se

p

a

r

a

ted by|

.

Th

e

 

P

OSI

X [

[

=c=]

]a

nd[

[

.

c

.

]

]nota

ti

ons for sa

me

-

w e

i

g

h

t

c

h

a

r

a

cters a

nd coll

a

ti

ng

 

e

le

ments a

re accepte

d.Th

e

nota

ti

on [

[

:

cl

a

ss

:

]

]def

i

nes ch

a

r

a

c

te

r

 

cl

a

sse

s:

a

lnum

a

l

pha

nume

r

i

c

low e

r

low e

r

-

c

a

se

a

lpha

a

l

phabe

t

i

c

print

pr

inta

bl

e

blank

space or

 

ta

b

punct

punc

tua

tion

cntrl

contr

ol

spa

c

e

w hite

spa

ce

dig

it

deci

ma

l

uppe

r

uppe

r

-

c

a

se

g

raph

non-

spaces

xdig

it

h

e

x

a

deci

ma

l

Th

r

e

es hoptoptions a

f

f

e

ct 

pa

tte

r

ma

tch

i

ng

.

dotg

lob

i

ncl

ude

 

f

i

l

e

w h

ose

 

na

me

beg

i

w ith.

noc

a

se

g

lob

i

g

nore ca

se

 

w hen 

ma

tch

i

ng

nullg

lob

re

move

 

pa

tte

r

ns  

th

a

don’

t

 

ma

tch

W hen expandi

ng

 f

i

l

e

na

me

s,.a

nd .

.a

r

e

 i

g

nored,

f

i

l

ena

me

ma

tch

i

ng

 

the pa

tterns 

i

n $

G LOBIG N OREa

r

e

a

lso 

i

g

nored a

nd a l

e

a

di

ng.

must 

be 

s uppl

i

ed 

i

the

pa

ttern to ma

tc

h

 f

i

l

ena

me

s th

a

t beg

i

n w ith ..

H ow eve

r

,se

tti

ng G LOBIG N ORE ena

bl

e

s thedotg

lob

option.

 

I

ncl

ude.

* i

n G LOBIG N ORE to g

e

t th

e

 

de

f

a

ul

t

b

e

h

a

vi

or

.

P

ATTERNS

Va

r

ia

bl

e

 

na

me

s a

r

e

 made up of

 

le

tte

r

s,

 

d

i

g

its a

nd

unde

r

score

s.

 Th

eyma

y

 

not sta

rtw ith

 

a

 

di

g

it.

 

Th

er

e

 

i

s

no 

l

i

mit 

on 

the 

l

eng

th

 

of

 

a

 

va

r

ia

bl

e

 

na

me,

 

a

nd 

the 

c

a

se

of

 

le

tte

r

i

s si

g

ni

f

ica

nt.

VA RI

A BLE N A MES

A ssi

g

nments to i

nte

g

e

r va

ri

a

bl

e

s underg

o

 

a

rithme

ti

c

eva

l

ua

tion.

 

Va

ria

b

le

 

a

ssi

g

nments h

a

ve one of

 

the

f

ol

l

ow i

ng

 

f

orms.

na

me

=w o

r

d

se

tna

metow o

r

d

na

me

[

i

nde

x

]=w o

r

d

se

e

le

menti

nde

xof

 

a

r

r

a

yna

metow o

r

d

na

me

=(

w o

r

d.

.

.

)

se

t i

nde

x

ed a

r

r

a

yna

metow ords

na

me

=(

 

[

num

]

=w o

r

d.

.

.

)

se

g

i

ve

i

ndi

ces of

 

a

r

r

a

yna

metow ords

VA RI

A BLE ASSI

G N MEN T

9

$

n

use positi

ona

pa

ra

me

te

rn,

n 9

$

{n}

use positi

ona

pa

ra

me

te

rn

$

*

a

l

l

 

positi

ona

l

 

pa

ra

me

te

r

s

$

@

a

l

l

 

positi

ona

l

 

pa

ra

me

te

r

s

"

$

*

"

equi

va

l

ent to"

$

1

 

$

2 .

.

.

"

"

$

@"

equi

va

l

ent to"

$

1

"

 

"

$

2".

.

.

$

#

number of positi

ona

pa

ra

me

te

r

s

options to sh

el

l

 

or byse

t

$

?

va

l

ue 

r

e

tur

ned by

 

l

a

st c

omma

nd

$

$

proce

ss 

number of current sh

e

l

l

$

!

proce

ss nu

mber

 of

 

la

st ba

ck

g

round

cmd

$

_

na

me

 

of

 pr

og

r

a

i

n e

nvir

onment a

t

sta

r

tup. Va

lue of

 

la

st positi

ona

l

a

r

g

ument in 

l

a

st c

omma

nd.

Name of

chang

e

ma

i

l

 

f

i

l

e

 

i

n $

MA I

LP

ATH

$

a

uto_

r

e

sume

ena

bl

e

use

 

of

 

sing

l

e

-

w ord

comma

nds to 

ma

tc

h

 

s topped 

j

obs 

f

or

f

ore

g

roundi

ng

.

 W ith

 

a

 

va

l

ue ofe

x

a

ct,

the w ord must e

x

a

c

tly

 

ma

tch the

comma

nd use

to sta

rtthe 

j

ob.

W ith

ava

l

ue ofs ubstring

,

the 

ty

ped 

w or

d

ca

n be

 

a

 

s ubstr

i

ng

 

of

 

the 

comma

nd,

l

i

k

e%?str

i

ng

$

BA SH

f

ul

l

 

f

i

l

e

 

na

me use

to 

i

nvok

eba

sh

$

BA SH _ENV

i

n norma

non-

i

nte

r

a

c

ti

ve 

sh

e

l

l

s only

,

va

l

ue i

s va

r

ia

bl

e

,

 

comma

nd and

a

rithme

ti

c substituted f

or

 pa

th of

sta

r

tup f

i

l

e

 

(

Se

e I

nvoca

t

i

on And

St

a

r

 

tup)

$

BA SH _

VERSI

ON

th

e

 

versi

on ofba

sh

$

BA SH _VERSINFO[

0

]

the ma

j

or versi

on number

(

r

e

l

e

a

se

)

$

BA SH _VERSINFO[

1

]

the mi

nor ve

r

si

on number

(

ve

rsi

on)

$

BA SH _VERSINFO[

2]

the pa

tc

hl

evel

$

BA SH _VERSINFO[

3]

the bui

l

d ve

rsi

on

$

BA SH _VERSINFO[

4]

the 

re

le

a

se

 

sta

tus

$

BA SH _VERSINFO[

5]

sa

me

 

a

s $

MA CH TYPE

$

CDPATH

se

a

rc

h pa

th forcdcomma

nd

$

DI

RSTA CK[

*

] a

rra

y

 va

r

ia

ble conta

i

ni

ng

 the pus h

d

a

ndpopddir

e

ctory

 

sta

c

k

$

EN V

i

i

nte

r

a

c

ti

ve POSI

mode 

sh

ell

s,

 

or

w hen 

i

nvok

ed a

s sh

,

va

l

ue 

i

s va

r

ia

bl

e,

comma

nd and

 

ar

i

t

hme

tic substitute

d

f

or pa

th

 

of

 

sta

rtup 

f

i

le

$

EUI

D

th

e

 

ef

f

e

ctive 

us er

 

id 

(

r

e

a

donl

y

)

$

FCED I

T

def

a

ult 

edito

r

 

f

o

r

 

thef

ccomma

nd 

(

no

def

a

ult 

va

l

ue)

$

FI

G N ORE

colon-

se

pa

r

a

te

d

 

l

i

st 

of

 

s uf

f

i

x

e

s   g

i

vi

ng

the 

se

of

 

f

i

le

na

me

to i

g

nor

e

 

w hen

doi

ng

  f

i

l

e

na

me compl

e

ti

on usi

ng

r

e

a

dline

$

G LOBIG N ORE colon-

se

pa

r

a

te

d

 

li

st 

of

 

pa

tterns g

i

vi

ng

the 

se

of

 

f

i

le

na

me

to i

g

nor

e

 

w hen

doi

ng

 

pa

tte

r

ma

tchi

ng

$

G ROUPS[

*

]

readonly

 

a

rra

y

 

va

r

ia

bl

e

 

w ith 

the 

l

i

st

of

 

g

roups th

e

 

u

ser be

l

ong

s to

$

histc

h

a

rs

c

h

a

r

a

c

te

r

s th

a

t contr

ol csh

-

sty

l

e

hi

story

 (

def

a

ult: !

ˆ

#

)

.

 

Se

e H i

st

or

 

y

Subst

i

t

ut

i

on

PRE-

DEFI

N ED 

VA RI

A BLES

1

0

$

H I

STCMD

hi

story

  number

 

o

f

 

the  cur

r

ent

comma

nd

$

H I

STCONTROL w ith

 

a

 

va

l

ue ofig

nore

spa

ce,do not

ente

r

 li

nes th

a

t beg

i

n w ith

 

s paces

i

nto the h

i

story

 

f

i

l

e

.W ith

 

a

 

va

l

ue of

ig

nore

dups,do not e

nte

r

 

a

 l

i

ne 

th

a

t

ma

tch

es the pr

e

vi

ous li

ne. Use

ig

nore

bothto combi

ne both

 

options

$

H I

STFI

LE

w h

er

e comma

nd h

i

stor

y

 

i

s store

d

$

H I

STFI

LESIZE ma

x

i

mum 

number

 

o

f

 

lines to k

e

e

i

n

$

H I

STFI

LE

$

H I

STI

G N ORE

col

on-

se

pa

r

a

ted 

l

i

st 

of

 

pa

tte

r

ns;

 

i

f

 

the

cur

r

ent li

ne 

ma

tc

h

e

s a

ny

 

of

 

th

em,

 

the

l

i

ne 

i

s   not 

ente

r

e

d

 

i

the hi

story

 

f

i

l

e.

& represe

nts th

e

 l

a

st hi

story

 li

ne.

Pa

tterns 

must 

ma

tch 

the 

w h

ole

 

l

i

ne

$

H I

STSI

ZE

number

 of

 pr

e

vi

ous comma

nds to

k

e

e

p ava

i

l

a

bl

e

 

w hi

l

eba

shi

s runni

ng

$

H OME

h

ome

 

dir

e

ctory

 

f

orcd comma

nd a

nd

va

l

ue use

f

or ti

l

de expansi

on

$

H OSTFILE

f

i

l

e

 

i

f

orma

t of/

e

tc/

h

osts to use

 

f

or

h

ostna

me compl

e

ti

on

$

H OSTNA ME

na

me

 

of

 

the 

cur

r

ent 

h

ost

$

H OSTTYPE

str

i

ng

 

de

scr

ibi

ng

 

the 

cur

r

ent 

h

ost

$

IFS

f

i

e

l

d s epa

r

a

tors 

(

spa

c

e

,

ta

b,

new line

)

$

I

G N OREEOF

f

or 

i

nte

r

a

c

ti

ve sh

e

l

ls,

 

the number

 

of

consecutive  EOFs  th

a

t must be

entered be

f

or

eba

sha

ctua

l

l

y

 

e

x

its

$

I

NPUTRC

na

me of r

e

a

dline sta

r

tup

f

i

l

e,

ove

r

r

i

des ˜

/

.

inputrc

$

LA N G

na

me

 

of

 

c

ur

r

ent loca

l

e

$

LC_ALL

cur

r

ent

 

loca

le

;

 

o

v

e

r

ri

des $

LA N G a

nd

oth

e

r$

LC_va

r

ia

bl

es

$

LC_COLLATE

cur

r

ent

 

loca

l

e

 

f

or ch

a

r

a

c

ter col

l

a

ti

on,

i

ncl

ude

s sor

ti

ng

 resu

lts of

 

f

i

l

e

na

me

e

x

pansi

on

$

LC_CTYPE

cur

r

ent loca

l

e

 f

or ch

a

r

a

c

te

r

 

cla

ss

f

unc

ti

ons (

se

ePa

t

t

er

 

ns)

$

LC_

MESSA G ES cur

r

ent l

oca

le

 f

or tra

nsla

ti

ng $

"

.

.

.

"

str

i

ng

s

$

LINENO

l

i

ne number

 

of

 

li

ne bei

ng

 

e

x

e

cuted 

i

n

scr

ipt or f

unc

ti

on

$

MA CH TYPE

astr

i

ng

 

i

n G N U cpu-

compa

ny

-

sy

ste

m

f

or

ma

t de

scri

bi

ng

  the  ma

chi

ne

r

unni

ngba

sh

$

MA I

L

na

me

 

of

 

a

 

ma

i

l

 

f

i

l

e

,

 

i

f

 

a

ny

$

MA I

LCHECK

check

 f

or ma

i

l

 eve

r

y n seconds (

60

def

a

ult)

$

MA I

LP

ATH

f

i

l

e

na

me

to ch

eck

 

f

or ne

w   ma

i

l

;

 

uses

:se

pa

r

a

tor;f

i

l

e

na

mema

y

 

be 

f

ol

l

ow e

d

by ?me

ssa

g

e

; $

_ i

n

me

ssa

g

e i

s

ma

tch

e

d ma

i

l

 f

i

l

e

 

na

me

.Over

r

i

des

$

MA I

L

$

OLD PW D

pr

e

vi

ous 

w ork

i

ng

 

dir

e

ctory

$

OP

TA RG

va

l

ue of

 

l

a

st a

r

g

ument 

proce

sse

d by

g

etopts

$

OPTERR

i

f

 se

t to 1

,

 di

s pl

a

y

 error me

ssa

g

e

s

f

r

om g

etopts (

de

f

a

ult:1

)

$

OPTIND

i

nde

x

 

of

 

l

a

st a

rg

ument 

proce

sse

d by

g

etopts

PRE-

DEFI

N ED 

VA RI

A BLES 

(

continued)

1

1

$

OSTYPE

str

i

ng

 

de

scr

i

bi

ng

 

the

oper

a

ti

ng

  sy

ste

m  r

unni

ng

ba

sh

$

PATH

comma

nd 

se

a

rc

h pa

th

$

PI

PESTATUS[

*

]

a

rra

y

 

va

r

i

a

bl

e conta

i

ni

ng

 

e

x

i

t

sta

tus va

l

ues f

r

om 

proce

sse

s

i

the 

most r

ece

ntly

 

e

x

ecute

d

f

ore

g

round pi

peli

ne

$

PPI

D

proce

ss 

i

d of

 

sh

el

l

s parent

$

PROMPT_

COMMA N D

comma

nd 

to 

r

un be

f

ore

 

e

a

ch

pr

ima

r

y

 

prompt

$

PS1

pr

ima

ry

 

prompt stri

ng

(

)

$

PS2

seconda

ry

 

prompt str

i

ng

 

(

>)

$

PS3

se

lect

comma

nd pr

ompt

str

i

ng

 

(

#

?)

$

PS4

tr

a

ci

ng

 

prompt str

i

ng

 

(

+

)

$

PW D

cur

r

ent 

w ork

i

ng

 

dir

e

ctory

$

RA N DOM

se

t e

a

c

h

 

ti

me

 

it’

s referenced,

$

REP

LY

se

t by

 the se

lect a

nd r

e

a

d

comma

nds

$

S ECONDS

numbe

r of se

c

onds si

nce s h

e

ll

i

nvoca

tion

$

SH ELL

na

me

 

of

 

th

i

s sh

ell

$

SH ELLOPTS

col

on-

se

pa

ra

te

d

 l

i

st of

 

the

ena

bled 

sh

e

l

l

 options forse

t

$

SH LVL

i

ncre

mented by

 

one

 

f

or

 

e

a

ch

s ub-

ba

sh

$

TI

MEFORMA T

f

orma

t stri

ng

 f

or outpu

t of

time

k

e

y

w ord.

 

Sp

e

ci

a

l

constr

ucts 

i

ntr

oduce

d by%.

%[

p]

[

l]

R

el

a

pse

d secs

%[

p]

[

l]

U

us er

 

CPU secs

%[

p]

[

l]

S

sy

ste

m C PU secs

%P

CPU perc

enta

g

e

%%

l

i

ter

a

l%

Optiona

lpg

i

ve

s the pr

e

ci

si

on,

the number of dig

its a

f

te

r

 

th

e

deci

ma

l poi

nt;

 it mus t be

betw e

e

n 0

 

a

nd 3.Optiona

ll

produce

s a

 

l

ong

er

 

f

orma

t,

 

i

n

the 

f

or

m MMmSS.

FF

s

$

TMOUT

number of seconds to w a

i

t

dur

ing

 

prompt 

bef

or

e

te

rmi

na

ting

$

UI

D

the 

r

e

a

us er

 

i

(

r

e

a

donl

y

)

PRE-

DEFI

N ED 

VA RI

A BLES

(

cont

i

nued)

Func

ti

ons run 

i

the 

sa

me proce

ss a

the 

ca

l

l

i

ng

 

scr

ipt,

a

nd 

sh

a

r

e

 

the open 

f

i

l

e

s a

nd 

cur

r

ent 

dir

e

ctory

.Th

e

y

a

c

c

e

ss 

th

ei

r

 

pa

ra

me

te

r

li

k

e

 

a

 

scr

ipt,

 

vi

a$

1

,

$

2 a

nd 

so

on.

$

0doe

s   not c

h

a

nge.

re

turn ma

y

 

be use

i

nsi

de 

a

f

unc

ti

on or .scr

i

pt.

 Func

ti

ons sh

a

r

e

 

tra

ps  

w ith 

the

pa

r

e

nt scri

pt,

 e

x

ce

pt f

orDEBUG .Func

ti

ons 

ma

y

 be

recursi

ve

,

 

a

nd 

ma

y

 

h

a

ve 

l

oca

va

r

ia

bl

e

s,

 

decl

a

red us i

ng

dec

la

re,

loca

l,ortypese

t.

Func

ti

ons 

ma

y

 

be expor

te

d

i

nto th

e

 

e

nvir

onment 

w ith

.

FUNCTI

ONS

1

2

background image

Re

dir

e

ctions a

re done

 

le

f

t to

 

ri

g

ht,

 

a

f

te

r

 

pi

pes a

re se

t

up.

 Def

a

ul

tf

i

l

e de

scr

iptors a

restdin a

ndstdout.Fi

l

e

descr

iptors above 2 a

r

e

 

ma

rk

ed cl

ose-

on-

e

x

ec.

&>w o

r

d

se

ndstdouta

ndstde

rrtow o

r

d

>&w o

r

d

se

ndstdouta

ndstde

rrtow o

r

d

[

n]

<f

i

l

e

usef

i

l

ef

or 

i

nput

[

n]

>f

i

l

e

usef

i

l

ef

or output

[

n]

>|

f

i

l

e

l

i

k

e>,

but overri

des noclobber

[

n]

>>f

i

l

e

l

i

k

e>but a

ppe

nd 

tof

i

l

ei

f

 

it e

x

i

sts

[

n]

<>f

i

l

e

open f

i

l

ef

or re

a

d/

w r

i

te

 

(

def

a

ult:

 

f

d

0

)

[

n]

<&m

dupl

i

ca

te

 

i

nput f

i

l

e descr

iptor from m

[

n]

>&m

dupl

i

ca

te

 

o

u

tpu

t file

 

d

e

scriptor from m

[

n]

cl

ose

 

i

nput f

i

l

e descr

iptor

[

n]

cl

ose

 

output f

i

l

e descr

iptor

[

n]

<<w o

r

d

i

nput c

ome

f

r

om 

the 

sh

e

l

l

 

scr

ipt;

 

tr

e

a

a

 

li

ne 

w ith

w o

r

da

EOF 

on 

i

nput.

I

f

 

a

ny

 

ofw o

r

di

s   quoted,

 

no

additi

ona

proce

ssi

ng

 

i

s   done on 

i

nput 

by

 

the 

sh

e

l

l

.

Oth

er

w i

se

:

• dova

r

i

a

bl

e

,

 

c

omma

nd,

 

a

r

i

thme

tic substitutions

• i

g

nore

 

e

scaped new li

nes

• use\to quote\

,

$

,

`

,

a

nd 

f

i

rst c

h

a

r

a

c

ter ofw o

r

d

[

n]

w o

r

d

a

s a

bove,

 

but 

w ith 

l

e

a

di

ng

 

ta

b

i

g

nor

e

d

Of&>a

nd>&,

the 

f

i

r

st 

i

s   pr

e

f

e

r

r

e

d

.

 

I

t is e

q

u

iva

le

nt to

>w o

r

d

2>&1

.

I

NPUT/

OUTPUT

A l

l

 s ubstitutions a

nd I

/

O r

edir

e

ctions a

re performe

d

bef

ore

 

a

 

comma

nd 

i

s a

ctua

l

l

y

 

e

x

e

cuted.

ba

sh ma

i

nta

i

ns   a

n i

nte

rna

l h

a

s h

 ta

bl

e

 f

or ca

c

h

i

ng

e

x

te

rna

comma

nds.I

niti

a

l

l

y

,thi

s ta

bl

e

 

i

s e

mpty

.

A s

comma

nds a

re found by

 

se

a

rc

hi

ng

 

the dir

e

ctori

e

li

ste

d

i

n $

PATH ,

th

ey

 

a

re added to th

e

 

h

a

s h

 

ta

bl

e.

The 

comma

nd 

se

a

rc

h

 

or

der

 

is sh

el

l

 

f

unc

ti

ons f

i

r

st,

 

bui

lt-

i

n comma

nds second,

 

a

nd exte

rna

comma

nds (

f

ir

st 

i

n

the 

i

nte

rna

l

 

h

a

s h

 

ta

bl

e

,

 

a

nd 

then vi

a$

PATH )thir

d.

EX ECUTI

ON ORDER

Sig

na

h

a

ndl

i

ng

 

i

s   done 

w ith 

thetra

pbui

l

t-

i

n comma

nd.

Th

ew o

r

d a

r

g

ument 

descr

ibi

ng

 

code 

to e

x

e

cu

te upon

rece

i

pt of the 

si

g

na

l

 

i

s sca

nned 

tw i

ce byba

sh

;once

w hen 

thetr

a

p comma

nd 

i

s e

x

e

cuted,

 

a

nd a

g

a

i

w hen

the 

si

g

na

l

 

i

s ca

u

g

ht.

Th

er

e

f

o

r

e

 

it is b

e

st to

 

u

se

 

sing

le

quote

f

or thetra

p comma

nd.

 

Tr

a

ps a

re execu

ted 

i

n

order of si

g

na

number

.

You ca

nnot c

h

a

ng

e

 

the 

sta

tus

of

 

a

 

si

g

na

l th

a

w a

i

g

nored 

w hen 

the 

sh

e

l

l

 

sta

rted up.

Tr

a

ps on DEBUG h

a

ppe

n a

f

ter comma

nds a

re execu

ted.

Ba

ck

g

rounded comma

nds (

th

ose

 f

ol

l

ow ed by&)w i

l

l

i

g

nore

 

th

eSI

G I

N T a

ndSI

G QUI

T si

g

na

ls 

i

f

 

themonitor

option 

i

s tur

ned of

f

.

Oth

er

w i

se

,

 

th

ey

 

i

nhe

rit th

e

 

va

l

ues

of

 

the pa

r

entba

sh.

SI

G N A LS 

A ND 

TRAPS

A r

r

a

y

s i

n ba

sh h

a

ve no l

i

mits on the number

 of

e

le

ments.

 A r

r

a

yi

ndi

c

e

s sta

rt a

t 0

.A r

r

a

y

 

subscr

i

pts

ca

n be

 

a

r

i

thme

ti

c

 

e

x

pr

e

ssi

ons.A r

r

a

y

 e

le

ments 

need

not be contig

uous.ba

sh doe

s   not h

a

ve a

ssoci

a

ti

ve

a

rra

y

s.

A RRAYS

1

3

!pi

pe

l

i

ne

e

x

ecutepi

pe

l

i

ne

.I

fe

x

it 

sta

tu

w a

non-

zero,

 

e

x

i

t

zero.

 

I

f

 

e

x

it 

sta

tu

w a

zero,

 

e

x

it 

1

c

a

sew o

r

d

in [

[

(

]

pa

1

[

|

pa

2]

.

.

.

)l

i

st

;

;

]

.

.

.

e

sa

c

e

x

ecutel

i

sta

ssoci

a

ted 

w ithp

a

tth

a

ma

tches w o

r

d.

Fi

e

ld s pli

tti

ng

 

i

s   not 

done 

f

orw o

r

d.p

a

t i

s aba

sh

pa

ttern (

se

ePa

t

t

er

 

ns)

.|i

s   us ed 

to 

i

ndi

ca

te

 

a

n OR

conditi

on.

 

Us el

e

a

di

ng(i

fc

a

sei

i

ns i

de$

(

 

)

forna

me[

in w ords];dol

i

st

;done

se

quentia

l

l

y

 

a

ssi

g

e

a

chw o

r

dtona

mea

nd execute

l

i

st.I

f in w ords i

s mi

ssi

ng

 

use

 the positi

ona

l

pa

r

a

me

te

r

s

[

f

unc

tion]f

unc

(

{l

i

st

;}

def

i

ne 

f

unc

ti

on f

unc,

body

 

i

s l

i

st(

se

eFunct

i

ons)

ifl

i

st1

;then l

i

st2 [

;elifl

i

st3

;then l

i

st4]

.

.

.

[

;elsel

i

st5]

;f

i

i

f

 e

x

ecuting l

i

st1r

e

tur

ns successf

ul

 e

x

it sta

tu

s,

e

x

ecutel

i

st2 e

lse

 

.

.

.

se

lectna

me[

in w ords];dol

i

st

;done

pr

int a

 

menu ofw ords,

pr

ompt 

w ith$

PS3 a

nd 

read 

a

l

i

ne 

f

r

om stdin,

sa

vi

ng

 

it in $

REP

LY.

I

fthe 

l

i

ne 

i

s

the number of one of th

e

 

w ords,

 

se

t na

meto it,

oth

e

rw i

se

 

se

t na

meto NULL.Execu

te l

i

st.I

fin

w ords i

s mi

ssi

ng u

se

 the positi

ona

l pa

ra

me

te

r

s.

ba

sha

utoma

ti

ca

l

l

y

 

r

epr

ints the 

menu a

t the end of

the 

l

oop

time[ ]pi

pe

l

i

ne

e

x

ecute pi

pe

l

i

ne

;pr

int e

la

pse

d,

 

sy

ste

m a

nd use

r

time

s on stderr.

pr

int ti

me

i

n POSI

f

orma

t

Th

e$

TI

MEFORMA T va

r

ia

bl

e contr

ol

s the 

f

orma

t of

the output if

i

s   not 

us ed.

ba

shuse

th

e

 

va

l

ue

$

\

nrea

l

\

t%3lR\

nuse

r

\

t%3lU\

nsys\

t%3lS’i

f

 

th

er

e

 

i

s

no val

ue 

f

or$

TI

MEFORMA T

untill

i

st 

1

;dol

i

st 

2

;done

l

i

k

ew hilebut 

ne

g

a

te

 

the 

te

rmi

na

tion 

te

st

w hilel

i

st 

1

;dol

i

st 

2

;done

e

x

ecute l

i

st 

1

.I

f l

a

st comma

nd i

n l

i

st 

1h

a

d a

succe

ssf

ul

 e

x

it sta

tu

s,

 

e

x

e

cute l

i

st 

2 f

ol

l

ow ed by

l

i

st 

1

.

Re

pea

until la

st c

omma

nd 

i

n l

i

st 

1r

e

tur

ns a

n

unsucce

ssf

ul 

e

x

it 

sta

tus

(

(

.

.

.

)

)

a

rithme

ti

c eva

lua

tion,

 

li

k

ele

"

.

.

.

"

[

[

e

x

pr

e

ssi

on

]

]

eva

lua

tee

x

pr

e

ssi

on,

r

e

tur

n success f

ul 

e

x

it 

sta

tu

i

f

tr

ue

,

  unsucce

ssf

ul

 

i

f

 

f

a

l

se

  (

se

e Condi

t

i

ona

l

Expr

e

ssi

ons f

or de

ta

i

l

s)

(

l

i

st

)

e

x

ecutel

i

sti

n a

 

s ub-

sh

e

ll

{l

i

st

;}

e

x

ecutel

i

sti

the 

cur

r

ent sh

ell

CONTROL COMMA N DS

1

4

Us ed 

w ith 

the[

[

.

.

.

]

]compound 

comma

nd,

 

w hi

ch does

not 

do pa

ttern e

x

pansi

on or

 

w ord spl

i

tti

ng

.

str

i

ng

tr

ue 

i

fstr

i

ngi

s   not 

NULL

f

i

l

e

tr

ue 

i

ff

i

l

ee

x

i

sts 

( i

s   pr

e

f

e

r

r

e

d

)

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

block

 

devi

ce

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

ch

a

r

a

c

te

r

 

devi

ce

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

dir

e

ctory

f

i

l

e

tr

ue 

i

ff

i

l

ee

x

i

sts

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

reg

ul

a

r

 

f

ile

f

i

l

e

tr

ue 

i

ff

i

l

eh

a

s se

tg

i

d bit 

se

t

f

i

l

e

tr

ue 

i

ff

i

l

eg

roup 

i

s e

f

f

e

cti

ve 

g

i

d

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

sy

mboli

l

i

nk

f

i

l

e

tr

ue 

i

ff

i

l

eh

a

s stick

y

 

bit 

se

t

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

sy

mboli

l

i

nk

str

i

ng

tr

ue 

i

fstr

i

ngh

a

s   non-

zero 

l

eng

th

f

i

l

e

tr

ue 

i

ff

i

l

ee

x

i

sts a

nd 

w a

modi

f

ied 

si

nce

l

a

st r

e

a

d

opt

i

on

tr

ue 

i

fopti

oni

s on

f

i

l

e

tr

ue 

i

ff

i

l

eow ne

r

 

is e

f

f

e

ctive 

ui

d

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

f

i

f

o (

na

med pi

pe)

f

i

l

e

tr

ue 

i

ff

i

l

ei

s re

a

dabl

e

f

i

l

e

tr

ue 

i

ff

i

l

eh

a

s   non-

zero size

f

i

l

e

tr

ue 

i

ff

i

l

ei

s a

 

sock

e

t

f

i

l

e

d

e

s

tr

ue 

i

ff

i

l

e

d

e

s i

s a

 

te

rmi

na

l

f

i

l

e

tr

ue 

i

ff

i

l

eh

a

s se

tu

i

d bit 

se

t

f

i

l

e

tr

ue 

i

ff

i

l

ei

w r

i

ta

bl

e

f

i

l

e

tr

ue 

i

ff

i

l

ei

s e

x

e

cuta

bl

e

str

i

ng

tr

ue 

i

fstr

i

ngh

a

s zero 

l

eng

th

f

i

l

e

1

f

i

l

e

2

tr

ue 

i

ff

i

l

e

1

i

s   ne

w e

r

 

th

a

n f

i

l

e

2orf

i

l

e

2

doe

s   not 

e

x

i

st

f

i

l

e

1

f

i

l

e

2

tr

ue 

i

ff

i

l

e

1

i

s ol

der

 

th

a

n f

i

l

e

2orf

i

l

e

2

doe

s   not 

e

x

i

st

f

i

l

e

1

f

i

l

e

2

tr

ue 

i

ff

i

l

e

1

a

ndf

i

l

e

2a

re th

e

 

sa

me

 

f

i

le

str

i

ng

==pa

tte

r

n

tr

ue 

i

fstr

i

ngma

tches pa

tte

r

n

str

i

ng

!

=pa

tte

r

n

tr

ue 

i

fstr

i

ngdoe

s   not 

ma

tchpa

tte

r

n

str

i

ng

1

<str

i

ng

2

tr

ue 

i

fstr

i

ng

1

i

s   bef

orestr

i

ng

2

str

i

ng

1

>str

i

ng

2

tr

ue 

i

fstr

i

ng

1

i

s a

f

te

rstr

i

ng

2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

equal

s e

x

p2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

does   not equa

le

x

p2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

i

le

ss 

th

a

n e

x

p2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

i

s   g

rea

ter th

a

ne

x

p2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

i

le

ss 

th

a

n or equa

l toe

x

p2

e

x

p1

e

x

p2 tr

ue 

i

fe

x

p1

i

s   g

r

e

a

te

r

 

th

a

n or

equa

l toe

x

p2

(

e

x

pr

e

ssi

on

)

tr

ue 

i

fe

x

pr

e

ssi

oni

s true,

 

f

or g

rou

pi

ng

!e

x

pr

e

ssi

on

tr

ue 

i

fe

x

pr

e

ssi

oni

s f

a

lse

e

x

p1

&&e

x

p2 tr

ue 

i

fe

x

p1

A N D e

x

p2a

r

e

 

tru

e

e

x

p1

|

|e

x

p2

tr

ue 

i

fe

x

p1

ORe

x

p2i

s tr

ue

I

ff

i

l

ei

s /

dev/

f

d/

n,

then,

 

i

f

 

th

er

e

 

i

s   no/

dev/

f

ddir

e

ctory

,

f

i

l

e de

scr

iptor n i

s ch

eck

ed.Oth

er

w i

se

,

 

the r

e

a

l

/

dev/

f

d/

n f

i

l

e

 

i

s ch

eck

e

d.

 

Linux

,

 

Fr

e

e

BSD,

 

BSD/

OS (

a

nd

ma

y

be oth

er

s)

 

r

e

turn i

nf

o f

or

 

the i

ndi

ca

ted f

i

l

e

descr

iptor,

i

nste

a

d of

 

th

e

 

a

c

tu

a

l/

dev/

f

ddevi

ce 

f

i

l

e.

Both && a

nd |

| a

re short cir

cuit.

  Opera

nds

of

compa

r

ison oper

a

tors underg

o

 

a

rithme

ti

c eva

l

ua

tion.

For==a

nd!

=,

quote

 

a

ny

 

pa

r

tofpa

tte

r

n to tre

a

it 

a

a

str

i

ng

.

CON DI

TI

ON A L EXPRESSI

ONS

1

5

Th

ese comma

nds a

re execu

ted dir

e

ctly

 by

 

the 

sh

e

l

l

.

A l

most a

l

l

 

acce

pt

to 

ma

rk

 

th

e

 

e

nd of

 

options.

.

f

i

l

e

source f

i

l

e

rea

d

 

a

nd

 

e

x

e

cute

 

c

omma

nds f

r

om

f

i

l

e

. I

f

a

rg

uments,

 

sa

v

e

 

a

nd re

store positi

ona

l pa

ra

ms.

Se

a

rch$

PATH ;i

fnoth

i

ng

 

f

ound,

 

look

 

i

the 

cur

r

ent

dir

e

ctory

: nul

l

 

comma

nd;

 

re

turns 0

 

e

x

it 

sta

tus

[ se

ete

st

a

li

a

s [ ][

na

me

[

=va

l

ue

].

.

.

]

c

re

a

te

 

a

n a

li

a

s.W ith no a

r

g

uments,

 pr

int a

ll

a

li

a

se

s.

 

W ithna

me

,

pr

int a

l

i

a

s va

l

ue 

f

orna

me

pr

inta

lia

s bef

ore

 

e

a

c

h

 

a

l

i

a

s

bg[

j

obi

d]

putj

obi

di

th

e

 

ba

ck

g

round

bind[

ma

p][

]

bind[

ma

p][

f

unc][ k

e

y

se

q][

f

unc]

bind[

ma

p]

f

i

l

e

bind[

ma

p]k

e

y

se

q

:

f

unc

di

s pl

a

y

 a

nd/

or

 modi

f

y r

e

a

dline f

unc

ti

on a

nd k

ey

bi

ndi

ng

s.

 

Th

e

 

sy

nta

x

 

i

s sa

me

 

a

s for˜

/

.

inputrc

f

i

l

e

read ne

w  

bi

ndi

ng

s f

r

om f

i

l

e

l

i

st the na

me

s of

 

a

llr

e

a

dlinef

unc

ti

ons

ma

p

us e

 

th

e

 

k

ey

ma

pma

p

li

str

e

a

dlinef

unc

ti

ons a

nd bi

ndi

ng

s

f

or

 

r

e

-

r

e

a

di

ng

li

str

e

a

dlinef

unc

ti

ons a

nd bi

ndi

ng

s

f

unc

sh

ow   w hi

ch k

e

y

i

nvok

ef

unc

k

e

y

se

q re

move bi

ndi

ng

f

ork

e

y

se

q

li

str

e

a

dlinek

e

y

 

se

quences a

nd 

ma

cros

f

or

 

r

e

-

r

e

a

di

ng

li

str

e

a

dlinek

e

y

 

se

quences a

nd 

ma

cros

f

unc

re

move

 

k

e

y

 

bi

ndi

ng

f

orf

unc

li

str

e

a

dlineva

r

ia

bl

e

 

na

me

s a

nd 

va

l

ues

f

or

 

r

e

-

r

e

a

di

ng

li

str

e

a

dlineva

r

ia

bl

e

 

na

me

s a

nd 

va

l

ues

brea

k[

n]

e

x

it f

r

om 

encl

osi

ngfor

,

w hile

,

untilorse

lectl

oop.

I

fni

s suppl

i

ed,

 

e

x

it f

r

om n’

th encl

osi

ng

 

loop

builtin sh

e

l

l

-

bui

l

t

i

n [a

r

g

s .

.

.

]

e

x

ecute sh

e

l

l

-

bui

l

t

i

n w i

th g

i

ven a

r

g

s a

nd r

e

tur

n

sta

tus.

 Usef

ulf

or the body

 

of

 

a

 

s h

e

l

l

 

f

unc

ti

on 

th

a

t

rede

f

ines a

 

bui

l

t-

i

n,

 

e

.

g

.

,

cd

cd[

][

di

r

]

chang

e

 

cur

r

ent dir

e

ctory

 to di

r(

$

H OME def

a

ult)

.

Do dir

e

ctory

 

pa

th

 

s e

a

rc

h usi

ng

 

va

l

ue of$

CDPATH

us e

 

l

og

i

ca

l

 

pa

th 

f

orcd 

.

.

,

$

PW D (

de

f

a

ult)

us e ph

y

si

ca

l

 

pa

th 

f

orcd 

.

.

,

$

PW D

I

f

 

both

 

are g

i

ve

n,

 

the 

l

a

st one on 

the 

comma

nd 

l

i

ne

w i

ns

cd [

]

chang

e

 

cur

r

ent 

dir

e

ctory

 

to$

OLDPW D

comma

nd[

]na

me[

a

r

g.

.

.

]

w ith

out

or

,

e

x

ecutena

mew i

th

 

a

r

g

uments a

r

g

us e

 

a

 

def

a

ult 

se

a

rc

h pa

th

,

 

not$

PATH

pr

int a

 

one

 

w ord de

scri

ption ofna

me

pr

int a

 

verbose

 

d

e

scri

ption ofna

me

continue[

n]

do next ite

r

a

ti

on of

 

encl

osi

ngfor

,w hile,untilor

se

lectl

oop.

 

I

fn i

s suppl

i

ed,

 

i

te

r

a

ten’

th encl

osi

ng

loop

BUI

LT-

I

N COMMA N DS

1

6

background image

dec

la

re[a

f

Firx][ ][

na

me

[

=va

l

ue

]

]

typese

t[a

f

Firx

][ ][

na

me

[

=va

l

ue

]

]

se

t a

ttr

i

bute

s a

nd va

lues of

 va

r

ia

bl

e

s.I

nsi

de

f

unc

ti

ons,

 

cre

a

te

 

ne

w  

copi

e

s of

 

th

e

 

va

r

ia

bl

e

s.

Usi

ng

+i

nste

a

d of tur

ns   a

ttr

i

bute

s of

f

.

W ith no na

mes

or a

ttri

bute

s,

 pr

int eve

r

y

 va

r

ia

bl

e

s na

me

 

a

nd

a

ttri

bute

s

na

mei

s a

n a

r

r

a

y

e

a

chna

mei

s a

 

f

unc

ti

on

don’

sh

ow  

f

unc

ti

on def

i

niti

ons (

bodi

e

s)

na

mei

s a

i

nte

g

e

r

;

 

a

rithme

ti

c

eva

lua

tion 

i

s   done upon a

ssi

g

nment

ma

r

kna

me

s r

e

a

donly

ma

r

kna

me

s f

orexport

dirs [

][

+

n][n]

di

s pl

a

y

 

the dir

e

ctory

 

sta

c

k

+

n

s how n’

th entr

y

 

f

r

om 

le

f

t,

n 0

n

s how n’

th entr

y

 

f

r

om 

r

ig

ht,

n

0

cl

e

a

r

 

the dir

e

ctory

 

sta

c

k

pr

int a

 

l

ong

er

 

f

orma

l

i

sti

ng

pr

int the 

sta

c

k

 

one entr

y

 

per

 

li

ne

pr

int the 

sta

c

k

 

one entr

y

 

per

 

li

ne,

 

w ith

i

nde

x

 

number

s

disow n [

][ ][

j

ob.

.

.

]

w ith no options,

 

r

e

move

 

na

me

dj

obs f

r

om 

the 

ta

bl

e

of

 

a

ctive 

j

obs

re

move

 

or

 

ma

rk

 

(

w ith

)a

l

l

 

j

obs

ma

r

k

 

e

a

chj

obto not re

c

e

i

ve 

aSI

G H UP

w henba

shte

rmi

na

te

s

us e

 

w ith

to 

ma

rk

 

j

ust r

unni

ng

 

j

obs

e

cho[

][

w ords]

e

chow ords;

i

s   not speci

a

l

e

x

pand 

\

-

e

sca

pes (

se

ee

c

h

o(

1

)

)

neve

r expand 

\

-

e

sca

pes

don’

t

 

output tr

a

i

l

i

ng

 

ne

w li

ne

pri

ntfi

more porta

bl

e

ena

ble[

][ f

i

l

e

][

na

me.

.

.

]

ena

bl

e

 

a

nd di

sa

bl

e

 

sh

el

l

 bui

l

t-

i

ns,

 or l

oad and

unl

oa

d ne

w  bui

l

t-

i

ns  f

r

om sh

a

red l

i

br

a

ry

 f

i

l

e

s.

Di

sa

bl

i

ng

 

a bu

i

lt-

i

n a

l

low s use

 

of

 

a

 

di

sk

 

f

i

l

e

 

w ith 

the

sa

me

 

na

me

 

a

s a

 

bui

lt-

i

n

pr

int 

a

l

l

 

bui

l

t

-

i

ns ,

 

w ith 

th

ei

r

 

sta

tus

del

e

te

 

a

 

bui

l

t-

i

l

oa

ded 

w ith

f

i

l

e

l

oa

d a new  

bui

lt-

i

n na

mef

r

om f

i

l

e

di

sa

bl

ena

me

,

orpr

int 

di

sa

bl

ed bui

l

t-

i

ns

w ith nona

me

s

pr

int e

na

bled bui

l

t-

i

ns

pr

int onl

y

 

POSIX speci

a

bui

l

t-

i

ns

eval[

w ords]

eva

lua

tew ords a

nd e

x

ecute

 

r

e

su

l

t

e

x

e

c[ na

me

][ ][

w ords]

e

x

e

cutew ords i

n pl

a

c

e

 

of

 

the 

sh

el

l

.I

f

 

r

edir

e

ctions

onl

y

,

chang

e

 

the 

sh

ell

s open 

f

i

l

es

usena

mef

ora

rg

v[

0

]

cl

e

a

r

 

the envir

onment f

ir

st

pla

c

e

 

a on a

rg

v[

0

](

l

i

k

el

og

i

n(

1

)

)

I

f

 

th

e

 

e

x

e

c

 

f

a

i

ls,

 

non-

i

nte

r

a

c

ti

ve 

sh

e

l

l

s e

x

it,

 

unle

ss

thes hoptopti

on e

x

ec

f

a

ili

s set

ex

it[

n]

e

x

it 

w ith 

r

e

tur

n val

uen.

Use$

? i

f

 

non

BUI

LT-

I

N COMMA N DS

(

cont

i

nued)

1

7

export[

][

na

me

[

=va

l

ue

].

.

.

]

w ith no a

r

g

uments,

 pr

int na

me

s a

nd va

l

ues of

e

x

porte

dva

r

ia

ble

s.

 Oth

er

w i

se

,

expor

 

tna

me

s to th

e

e

nvir

onment of comma

nds

na

me

s r

e

f

e

r

 

to functions

stop e

x

por

ti

ng

 

e

a

chna

me

pr

intexportbef

ore

 

e

a

ch va

r

ia

bl

e

f

c[ e

di

t

or

]

[

]

[

f

i

r

st[

l

a

st]

]

pr

int a

 

r

a

ng

e

 

of

 

c

omma

nds f

r

om f

i

r

sttol

a

stf

r

om 

l

a

st

$

H I

STSIZEcomma

nds

r

un e

di

tori

f

 

s uppli

ed;

 

i

f

 

not,

 

us e

 

f

i

r

st 

of

$

FCEDI

T,

$

EDI

TOR,

orvion

comma

nds;

 

e

x

e

cute

 

r

e

su

lt(

s)

l

i

st on s ta

ndard output 

i

nste

a

d of

 

editi

ng

don’

pr

int line number

s

reverse order of comma

nds

[

ol

d

=ne

w ][

comma

nd]

s ubstitutene

w f

orol

di

n comma

nd(

or

 

la

st c

omma

nd

i

f

 

nocomma

nd)

and execute

 

the 

resu

l

t

f

g[

j

obi

d]

putj

obi

di

the 

f

ore

g

round

g

etopts optstr

i

ng

 

na

me[

a

r

g.

.

.

]

pa

rse pa

ra

me

ters a

nd opti

ons (

se

eba

sh

(

1

)

)

h

a

sh[ ][ f

i

l

e

][

na

me

]

w ith

 

no a

r

g

uments,

 

pr

int th

e

 

h

a

s h

 

ta

ble conte

nts,

g

i

vi

ng

 

h

it 

count a

nd 

f

i

l

e

 

na

me

f

i

l

e

ente

rf

i

l

ef

orna

mei

th

e

 

h

as h

 

ta

bl

e

cl

e

a

r

 

the 

i

nte

rna

h

a

s h

 

ta

bl

e

A ssi

g

nment to$

PATH a

lso cle

a

r

s th

e

 

h

a

s h

 

ta

bl

e

h

elp[

pa

tte

r

n]

pr

int h

el

p.W ithpa

tte

r

n,pr

int h

el

p about a

l

l

 

the

comma

nds th

a

ma

tchpa

tte

r

n

history[

n]

[

f

i

l

e

]

history[ ]

a

r

g[

.

.

.

]

a

r

g[

.

.

.

]

w ith no options,

 pr

int the 

comma

nd hi

story

.A n

a

rg

ument ofn pr

ints 

onl

yn l

i

nes.

 

I

fs uppl

i

ed,

 

use

f

i

l

ei

nste

a

d of$

H I

STFI

LE

a

ppend ne

w  

hi

stor

y

 

l

i

nes to h

i

story

 

f

i

l

e

cl

e

a

r

 

the h

i

story

 

li

st

read ne

w  

hi

story

 

l

i

nes 

i

the 

f

i

l

e

 

i

nto th

e

i

nte

rna

hi

story

 

l

i

st

per

f

orm 

hi

story

 

s ubstitution a

nd pr

int

the 

r

e

sults

repl

a

c

e

 

i

nte

rna

hi

story

 

w ith conte

nts of

hi

story

 

f

i

le

pl

a

c

e

 

thea

r

g

s i

nto the h

i

story

 

l

i

st

f

or 

la

ter use

w r

i

te

 

th

e

 

i

nte

rna

h

i

story

 

to the 

f

i

le

j

obs [

][

j

obi

d.

.

.

]

comma

nd[

a

r

g

s .

.

.

]

l

i

st 

i

nf

orma

ti

on abou

t j

obs

a

l

so 

l

i

st 

proce

ss 

i

d

onl

y

 

l

i

st stopped or

 

e

x

ited 

j

obs

onl

y

 

li

st 

proce

ss 

g

roups

onl

y

 

li

st runni

ng

 

j

obs

onl

y

 

li

st stopped 

j

obs

repla

c

e

 

a

nyj

obi

di

the 

comma

nd 

l

i

ne

w ith 

the 

cor

r

e

spondi

ng

 

proce

ss g

roup I

D,

a

nd execute

 

th

e

 

comma

nd

BUI

LT-

I

N COMMA N DS

(

cont

i

nued)

1

8

k

ill[si

g

]j

obi

d.

.

.

k

ill[ si

g

na

me

][

si

g

num]j

obi

d.

.

.

se

nd SI

G TERM or g

i

ve

n si

g

na

l to na

me

d j

obi

ds.

Sig

na

ls a

re na

me

s li

sted 

i

n /

u

sr/

inc

lude

/

signa

l.

h

w ith

 

or

 

w ith

out the pr

e

f

ix

 

SI

G ’

.

 

Stoppedj

obs   g

e

t

a SI

G CON T f

ir

st i

f si

g i

s e

ither SI

G TERM or

SI

G H UP

[

si

g

s .

.

.

]

l

i

st si

g

na

l na

me

s a

nd/

or

 numbers.I

f si

g i

s   a

nume

ri

ca

e

x

it 

sta

tu

s,

 

pri

nt the 

si

g

na

l th

a

t k

i

l

l

ed 

the

proce

ss

let a

r

g.

.

.

eva

l

ua

te

 

e

a

cha

r

ga

s a

n a

r

i

t

hme

ti

c

 

e

x

pr

e

ssi

on;

 

e

x

it 

0

i

f

 the l

a

st e

x

pre

ssi

on 

w a

s non-

zero,

 

1

 

oth

e

rw i

se

(

se

eAr

i

t

h

met

i

cEva

l

ua

t

i

on)

loca

l[

na

me

[

=va

l

ue

].

.

.

]

c

re

a

te

 

v

a

ri

a

bl

e

w ith the g

i

ve

n val

ues l

oca

l to a

f

unc

ti

on.

 W ith no operands ,

 pr

int a

 li

st of

 

loca

l

va

r

i

a

bl

e

s.

 

Mustbe use

i

ns i

de a

 

f

unc

ti

on

logout

e

x

it 

a

 

l

og

i

n s h

ell

popd[ ][

+

n][n]

re

move entr

i

e

f

r

om 

the dir

e

ctory

 

stack

.W ith no

a

rg

uments,

 

r

e

move

 

the 

top e

ntry

 

a

ndcdth

er

e

+

n

re

moven’

th entr

y

 

f

r

om 

le

f

t,

n 0

n

re

moven’

th entr

y

 

f

r

om 

r

ig

ht,

n

0

don’

t

 

chang

e

 

dir

e

ctory

pri

ntff

o

r

ma

t[

a

r

g.

.

.

]

pr

int ou

tpu

li

k

e

 

A N SI

 

C printf

,

w ith ex

te

nsi

ons

%b

e

x

pand esca

pe 

se

quenc

e

i

n s tr

i

ng

s

%q

pr

int 

quote

d

 

stri

ng

 

th

a

t c

a

n be 

re

-

r

e

a

d

For

ma

t conversi

ons a

re reused a

s ne

e

ded

pus h

d[ ][

di

r

]

pus h

d[ ][

+

n][n]

add an entr

y

 to the dir

e

ctory

 sta

c

k

.W ith no

a

r

g

uments,

 

e

x

chang

e

 

the 

top tw o e

ntr

i

es

+

n

rota

te

 

th

e

 

sta

c

k

 

so th

a

t th

en’

th

entr

y

 

f

r

om 

le

f

i

s a

t the 

top,

n 0

n

rota

te

 

th

e

 

sta

c

k

 

so th

a

t th

en’

th

entr

y

 

f

r

om 

r

ig

ht i

s a

t the 

top,

n 0

don’

t

 

chang

e

 

dir

e

ctory

di

r

pushdi

ron 

the 

sta

c

k

 

a

ndcdth

er

e

pw d[

]

pr

int 

w ork

i

ng

 

dir

e

ctory

 

na

me

pr

int log

i

ca

pa

th 

(

def

a

ult)

pr

int 

phy

si

ca

pa

th

I

f

 

both

 

are g

i

ve

n,

 

the 

l

a

st one on 

the 

comma

nd 

l

i

ne

w i

ns

na

me

][

][ pr

o

mpt][

na

me

s .

.

.

]

r

e

a

dstdin a

nd a

ssi

g

to na

me

s.

$

IFS s pl

i

ts 

i

nput.

$

REP

LY i

s se

i

f

 

nona

meg

i

ve

n.

 Exi

t0unle

ss e

nd-

of

-

f

i

l

e

 

e

ncounte

r

e

d

read 

w ords 

i

nto 

i

nde

x

ed a

r

r

a

yna

me

user

e

a

dlinei

f

 

r

e

a

di

ng

 

f

r

om 

a

 

te

rmi

na

l

pr

intpr

o

mpti

f

 

r

e

a

di

ng

 

f

r

om 

a

 

te

rmi

na

l

bef

ore

 

r

e

a

di

ng

a

t e

nd of

 

li

ne does   not 

do 

li

ne

continua

ti

on

BUI

LT-

I

N COMMA N DS

(

cont

i

nued)

1

9

r

e

a

donly[

][

na

me

=va

l

ue.

.

.

]

ma

r

kna

me

s r

e

a

d-

onl

y

;

 

pr

int li

st 

i

f

 

nona

me

s

e

a

chna

memust 

be a

n a

r

r

a

y

e

a

chna

memust 

be a

 

f

unc

ti

on

pr

intr

e

a

donlybef

ore

 

e

a

ch va

r

ia

bl

e

re

turn [

n]

e

x

it f

unc

ti

on or.

scr

ipt 

w ith 

r

e

tur

n val

uen.

W ith no

n,

r

e

tur

n s ta

tus of

 

la

st comma

nd.

I

f

 

not i

f

unc

ti

on

or.

scr

ipt,

 

pr

int a

n error 

me

ssa

g

e

se

t[opti

ons][ opt

i

on][

w ords]

se

t f

la

g

s a

nd 

opti

ons (

se

eOpt

i

ons Tose

t)

.

w ords se

t

positi

ona

pa

ra

me

te

r

s

se

t[

+

opt

i

ons][

+

oopti

on][

w ords]

unse

t f

l

a

g

s a

nd 

options

s h

i

f

t[

n]

rena

me positi

ona

pa

ra

me

te

r

s;

 

$

n+

1

=$

1

 

.

.

.

nde

f

a

ults to 

1

s hopt[

][

opt

i

on.

.

.

]

pr

int or ch

a

ng

e

 

va

l

ues of

 

sh

el

l

 options.W ith no

a

r

g

uments,

 

pr

int sh

el

l

 

opti

on 

i

nf

orma

tion

onl

y

 

chang

e

opti

ons

pr

int se

tti

ng

s for re

-

r

e

a

di

ng

qui

e

mode;

 

e

x

it 

sta

tu

i

ndi

ca

te

s

option 

sta

tus

se

t (

ena

ble

)

 

g

i

ven opti

on;

 

w ith no

options,

 

pr

int th

ose

 

th

a

t a

re se

t

unse

t (

di

sa

bl

e

)

 

g

i

ve

n opti

on;

 

w ith no

options,

 

pr

int th

ose

 

th

a

t a

re unse

t

(

Se

eOpt

i

ons Tos hopt)

s us pend[ ]

s us pend 

the 

sh

e

l

l

 

untilSI

G CON T i

s rece

i

ved

f

orce

 

suspensi

on,

 

eve

f

or 

l

og

i

n s h

e

ll

te

st

eva

l

ua

te cond

iti

ona

l

 e

x

pr

e

ssi

ons (

se

e Opt

i

ons To

te

sta

ndCondi

t

i

ona

l

 

Expr

e

ssi

ons)

times

pr

int a

c

c

umul

a

ted pr

oce

ss 

times

tra

p[

][

w o

r

d][

si

g

s]

e

x

ecute w o

r

d i

f

 si

g

na

l

 

i

n si

g

s r

ece

i

ve

d.si

g

s a

r

e

numbers or si

g

na

na

me

s w ith or

 w ith

out ‘

SI

G ’

.

W ith no w o

r

d orsi

g

s,pr

int tr

a

ps.W ith no w o

r

d,

rese

tsi

g

s to e

ntry

 

def

a

ults.

I

fw o

r

d

si

g

s

to e

ntry

 

def

a

ults.I

fw o

r

d i

s the nul

l

 

str

i

ng

,

 

i

g

nore

si

g

s.

I

fsi

g

s i

s 0orEXI

T,

executew o

r

don e

x

it f

r

om

sh

el

l

.

 

I

f si

g

s i

s DEBUG ,r

un w o

r

d a

f

te

r

 

e

v

e

r

y

comma

nd.

pr

int 

a

 

li

st 

of

 

sig

na

na

me

s a

nd number

s

pr

int tr

a

ps 

w ith quoti

ng

type[

]na

me.

.

.

descr

ibe how  

the 

sh

e

l

l

 

i

nte

rpr

e

ts na

me

pr

int a

l

l

 

possi

ble

 

i

nte

rpr

e

ta

ti

ons

ofna

me

pr

int the na

me

 

of

 

the 

f

i

l

e

 

to e

x

e

cu

te

 

i

f

na

mei

s a

n ex

te

rna

prog

r

a

m

pr

int a

 

k

ey

w ord de

scri

bi

ngna

me

BUI

LT-

I

N COMMA N DS

(

cont

i

nued)

20

background image

ulimit[

ty

pe

][

opt

i

ons][

l

i

mi

t]

se

t or pr

int 

per

-

proce

ss 

l

i

mits

ty

pe(

de

f

a

ult is   both)

:

h

a

r

li

mi

t

sof

t

 

li

mi

t

opt

i

ons:

a

l

l

 

(

di

s pl

a

y

 

onl

y

)

cor

e

 

f

ile

 

size

k

’ofda

ta

 

se

g

ment

ma

x

i

mum 

f

i

l

e

 

size

k

’ofph

y

si

ca

me

mory

ma

x

i

mum 

f

i

l

e de

scr

iptor 

+

 

1

siz

e

 

of

 

pi

pe buf

f

e

r

s

k

’ofsta

ck

 

se

g

ment

cpu s econds
ma

x

 

proce

sse

f

or one

 

u

se

r

k

’ofvi

r

 

tu

a

lme

mor

y

i

s a

ssumed 

i

f

 

no options a

r

e

 

gi

ve

n.

The 

siz

e

 

f

or

i

i

n 51

2-

by

te

 

block

s;

 

th

e

 

oth

ers 

a

re 

i

n s iz

e

s of

1

0

24 

by

te

s

uma

sk[

][

ma

sk

]

se

t f

i

l

e

 

cr

e

a

ti

on per

mi

ssi

ons 

ma

sk

 

to comple

ment of

ma

ski

f

 

octa

l,

 

or sy

mboli

c va

l

ue a

i

n ch

mod.

W ith

no a

r

g

uments,

 

pr

int c

ur

r

ent 

ma

sk

.

A n 

octa

l

 

ma

sk

 

i

s

per

mi

ssi

ons to re

move

,

 a

 

sy

mboli

c ma

sk

 i

s

per

mi

ssi

ons to k

e

e

p

pr

int ou

tpu

t for re

-

r

e

a

di

ng

pr

int c

ur

r

ent 

ma

sk

 

i

n s y

mbol

i

c

 

f

orm

una

lia

s [ ][

na

me

s]

re

move

 

a

li

a

se

s na

me

s

re

move

 

a

l

l

 

a

l

i

a

se

s

unse

t[

][

na

me

s]

unse

t va

ri

a

bl

es na

me

s (

sa

me

 

a

s

)

unse

t f

unc

ti

ons na

me

s

unse

t va

ri

a

bl

es na

me

s

Unse

tti

ng

LI

N EN O, MA I

LCHECK, OPTARG ,

OPTIND,RA NDOM,SECON DS,TMOUT a

nd _

re

move

s th

ei

r

 speci

a

l

 me

a

ni

ng

,

 eve

n i

f

 us e

d

a

f

te

rw a

rds

w a

it[

j

obi

d.

.

.

]

w a

it f

or 

j

obj

obi

d;i

fnoj

ob,

w a

it f

or a

l

l

 

ch

i

l

dr

e

n

BUI

LT-

I

N COMMA N DS

(

cont

i

nued)

Th

ete

stcomma

nd,

 

a

nd 

its sy

nony

m [

.

.

.

]

,

a

re bui

l

t-

i

to

ba

sh.

The 

comma

nd a

ccepts 

a

l

l

 

of

 

the options 

l

i

ste

i

n

theCondi

t

i

ona

l

 

Expr

e

ssi

ons se

ction.

 H ow eve

r

,

si

nce 

i

t

 

i

s

acomma

nd,

 

options a

nd 

a

r

g

uments 

must 

be quote

d

 

to

g

et 

pr

oper

 

b

e

h

a

vi

or

,

a

nd nor

ma

pa

ttern e

x

pans i

on a

nd

f

i

e

l

d s pl

i

tti

ng

 

a

re done

.

Pa

renth

e

se

s used 

f

or groupi

ng

must 

be quote

d.

A r

i

thme

ti

c

 

e

x

pansi

on 

i

s   not 

done 

f

or

nume

ri

c oper

a

tors,

 

a

nd pa

ttern 

ma

tchi

ng

 

i

s   not 

done

f

or==a

nd!

=.

te

stcompl

i

e

w ith

 

POSI

X.

Th

e

a

nd

options   h

a

ve the 

f

ol

l

ow i

ng

 

me

a

ni

ng

s,

i

nste

a

d of

 

th

e

 

one

l

i

sted 

i

n Condi

t

i

ona

l

 

Expr

e

ssi

ons:

l

og

i

ca

A N D

l

og

i

ca

OR

OPTI

ONS 

TO te

st

21

Th

ese

tcomma

nd 

i

s compli

ca

te

d.

H e

r

e

 

i

s a

 

summa

ry

.

Use + i

nste

a

d of

to tur

n options of

f

.W ith no

a

rg

uments,se

t pr

ints the na

me

s a

nd va

l

ues of

 a

ll

va

r

ia

bl

e

s.

se

t[a

bBCefh

H k

mnpPtuvx

][oopti

on.

.

.

]

 

[

a

r

g.

.

.

]

a

utoma

ti

ca

l

l

y

 

e

x

por

tvar

i

a

bl

e

upon

a

ssi

g

nment

pr

int j

ob 

compl

eti

on 

me

ssa

g

e

s

i

mmedi

a

te

l

y

,

don’

w a

it f

or ne

x

t prompt

ena

ble br

a

c

e

 

e

x

pansi

on 

(

de

f

a

ult)

f

or

c

e>|to over

w r

i

te

 

f

or e

x

i

sti

ng

 

f

i

l

es

e

x

it 

upon non-

zero exit f

r

om 

a comma

nd

di

sa

ble pa

ttern e

x

pans i

on

sa

ve comma

nd 

l

oca

tions 

i

the

i

nterna

l

 

h

a

s h

 

ta

bl

e

 

(

d

e

f

a

ult)

ena

bl

e!

-

sty

l

e h

i

stor

y

 

(

def

a

ult)

pl

a

c

e

 

a

l

l

 

va

r

i

a

bl

e

 

a

ssi

g

nments 

i

n

the envir

onment (

obsol

e

te

)

r

un ba

c

k

g

round 

j

obs 

i

th

ei

r

 

ow n

proce

ss 

g

r

oup,

 

pr

int a

 

me

ssa

g

e

w hen 

th

ey

 

e

x

it;

 

se

t a

u

toma

ti

ca

l

l

y

 

f

or

i

nte

r

a

c

ti

ve 

sh

e

ll

s on 

j

ob 

contr

ol

 

sy

ste

ms

read comma

nds 

w ith

out 

e

x

e

cuting

 

them

(

i

g

nored 

i

f

 

i

nte

r

a

c

ti

ve)

se

t opti

ons;

 

w ith no a

r

g

uments,

 

pr

int

cur

r

ent se

tti

ng

s

a

llexport sa

me

 

a

s

braceexpa

nd

sa

me

 

a

s

e

ma

c

s

use

 

a

n e

ma

c

s-

sty

l

e

 

l

i

ne

editor (

def

a

ult)

erre

xit

sa

me

 

a

s

h

a

sh

a

ll

sa

me

 

a

s

histexpa

nd

sa

me

 

a

s

history

ena

bl

e h

i

story

ig

nore

e

of l

i

k

eI

G N OREEOF=1

0

k

ey

w ord

sa

me

 

a

s

monitor

sa

me

 

a

s

noclobbe

r sa

me

 

a

s

noexec

sa

me

 

a

s

noglob

sa

me

 

a

s

notif

y

sa

me

 

a

s

nounse

t

sa

me

 

a

s

onecmd

sa

me

 

a

s

phy

sica

l

sa

me

 

a

s

posix

obey

 

the 

POSIX 1

0

0

3.

2

sta

nda

r

d

pr

ivile

g

e

d sa

me

 

a

s

verbose

sa

me

 

a

s

vi

us e

 

avi

-

sty

l

e

 

l

i

ne editor

xtra

c

e

sa

me

 

a

s

don’

t r

e

a

d$

EN V,

donot ta

k

e

 

sh

e

ll

f

unc

ti

ons f

r

om 

e

nvir

onment,

 

a

nd 

i

g

nore

options 

i

n $

SH ELLOPTS e

nvir

onment

va

r

ia

bl

e

f

ol

low  

the phy

si

ca

dir

e

ctory

 

str

uctur

e

f

or comma

nds th

a

t c

h

a

ng

e

 

the dir

e

ctory

read and execu

te one comma

nd,

th

e

n ex

i

t

ma

k

e

 

it 

a

n e

r

r

or to su

b

stitute

 

a

n unset

va

r

ia

bl

e

pr

int input li

nes a

th

ey

r

e

 

r

e

a

d

OPTI

ONS 

TO se

t

22

pr

int c

omma

nds a

th

e

y

r

e

 

e

x

ecuted,

preceded by

 

e

x

panded va

lue of$

PS4.

Output i

s   quote

d

 

f

o

r

 

la

te

r

 

r

e

u

se

tur

n of

f , ,

s top 

l

ook

i

ng

 

f

or fla

g

s;

a

ny

 

re

ma

i

ni

ng

 

a

r

g

s se

t th

e

positi

ona

pa

ra

me

te

r

s

do not c

h

a

ng

e

 

f

la

g

s;

 

se

t pos iti

ona

l

pa

ra

me

te

r

s from 

a

rg

ument li

st;

w ith no a

r

g

s,

 

unse

t the positi

ona

l

pa

r

a

me

te

r

s

OPTI

ONS 

TO se

t

(

cont

i

nued)

Th

es hoptcomma

nd 

se

ts 

or unse

ts a

 

number

 

of

 

options

th

a

a

f

f

e

ct 

h

ow ba

shbeh

a

ves.

 

Th

i

s se

cti

on descr

ibes

e

a

ch option’

s e

f

f

e

ct 

w hen e

na

bled.

Unl

e

ss 

note

d

,

 

th

e

y

a

re a

l

l

 

di

sa

bl

ed by

 

def

a

ult.

cda

ble

_

va

rs

tr

e

a

t a

n a

r

g

ument tocdth

a

t i

s   not 

a

 

dir

e

ctory

 

a

a

va

r

i

a

bl

e

 

w h

ose va

l

ue 

i

s the dir

e

ctory

 

na

me

cds pe

ll

a

tte

mpt to cor

r

e

ct mi

nor spel

l

i

ng

 errors i

n

a

rg

uments to cd.Er

r

ors tri

ed a

re tra

nspose

d

c

h

a

r

a

c

te

r

s,

 

a

  mi

ssi

ng

 c

h

a

r

a

c

ter or a

n e

x

tra

c

h

a

r

a

c

te

r.

Onl

y

 

obey

ed 

i

i

nte

r

a

c

ti

ve 

sh

e

l

l

s

check

h

a

sh

check

 

th

a

a comma

nd 

i

th

e

 

h

a

s h

 

ta

bl

e

 

still 

e

x

i

sts

bef

ore

 

try

i

ng

 to e

x

e

cute

 it.I

f

 

it doe

s n’

t

,

 se

a

rch

$

PATH

check

w ins ize

check

 the 

w i

ndow  siz

e

 

a

f

ter ea

c

h

 

c

omma

nd and

upda

te$

LINES a

nd$

COLUMN S

cmdhist

a

tte

mpt to sa

ve a

l

l

 

l

i

nes of

 

a

 

multi

-

l

i

ne 

comma

nd 

i

n

the h

i

story

 

f

i

l

e

 

a

s one 

l

i

ne,

 

f

or e

a

sy

 

re

-

editi

ng

dotg

lob

i

ncl

ude

 f

i

l

e

s w h

ose

 

na

me

s beg

i

n w ith.i

n pa

th

e

x

pansi

ons

e

x

ec

f

a

il

k

e

e

p non-

i

nte

r

a

c

ti

ve 

sh

e

ll

s f

r

om 

e

x

iti

ng

 

w hen e

x

e

c

f

a

i

l

s

expa

nd_

a

lia

se

s

e

x

pand a

l

i

a

se

s a

s descr

i

bed i

n Al

i

a

se

s.Ena

ble

d

a

utoma

ti

ca

l

l

y

 

i

i

nte

r

a

c

ti

ve 

sh

e

l

l

s

ex

tg

lob

ena

bl

e

 

th

e

 

e

x

tended pa

ttern 

ma

tc

hi

ng

 

f

a

ci

l

i

tie

(

se

e

Pa

t

te

r

 

ns)

hista

ppend

a

ppend 

the 

cur

r

ent 

hi

story

 

to$

H I

STFI

LEupon e

x

it,

i

nste

a

d of

 

ove

r

w r

i

t

i

ng

 

i

t

histreedit

i

f

 

usi

ngr

e

a

dli

nea

nd a h

i

stor

y

 

s ubstitution 

f

a

i

l

s,

 

the

us er ca

re

-

edit the 

li

ne

histver

i

f

y

i

f

 usi

ng r

e

a

dline,l

oa

d the resu

lts of

 h

i

story

s ubstitution 

i

ntor

e

a

dlinef

o

r

 

f

ur

th

er editi

ng

h

ostc

omple

te

i

f

 

usi

ngr

e

a

dline

,

atte

mpt 

h

ost compl

e

ti

on on 

w or

d

conta

i

ni

ng@

huponex

it

se

ndSI

G H UPto a

l

l

 

j

obs 

w hen ba

she

x

its

inte

r

a

c

tive_

comments

i

i

nte

r

a

c

ti

ve 

sh

e

ll

s,

 

a

 

w ord

 

sta

rti

ng

 

w ith#sta

r

ts a

comment.

 

Ena

bl

e

dby

 

def

a

ul

t

OPTI

ONS 

TO s hopt

23

lithist

i

f cmdhist i

s a

l

so e

na

bled,

 

sa

ve  multi

-

l

i

ne

comma

nds 

w ith ne

w l

i

nes,

 

not se

mi

-

col

ons

ma

ilw a

rn

pr

int a

 

w a

rni

ng

 

me

ssa

g

e

 

i

f

 

a

 

f

i

l

e be

i

ng

 

check

ed 

f

or

ma

i

l

 w a

s a

c

c

e

sse

d s i

nce

 the l

a

st ti

me

 it w a

s

check

e

d

noc

a

se

g

lob

do a

 c

a

se

-

i

nse

nsiti

ve ma

tch w hen expandi

ng

pa

thna

mes

nullg

lob

re

move

 

pa

tterns th

a

t don’

ma

tc

h

 

a

ny

 

f

i

l

e

,

 

i

ns te

a

d

of

 

le

a

vi

ng

 

th

em 

unchang

e

i

the 

comma

nd 

l

i

ne

promptva

rs

do pa

ra

me

te

r

 

e

x

p

a

nsi

on on the prompt va

ri

a

bl

es

bef

ore pri

nting

 

th

em.

Ena

bl

ed by

 

def

a

ul

t

s h

i

f

t_

ve

rbose

pr

int a

n error me

ssa

g

e

 w hen the s h

i

f

t

 count is

g

rea

ter th

a

n th

e

 

nu

mbe

r

 

o

f

 positi

ona

pa

ra

me

te

r

s

sourcepa

th

use $

PATH t

o

 

f

ind sh

e

l

l

 

f

i

l

e

g

i

ven to the.a

nd

sourcecomma

nds.

 

Ena

bl

e

dby

 

def

a

ul

t

OPTI

ONS 

TO s hopt

(

cont

i

nued)

#

sta

r

tof

 

c

omment;

 

te

rmi

na

ted by

 

new l

i

ne

|

(

pi

pe)

 

c

onnec

ts tw o comma

nds

;

comma

nd 

se

pa

r

a

tor

&

r

un proce

ss 

i

n back

g

round; de

f

a

ul

tstdin

f

r

om /

dev/

nulli

f

 

no 

j

ob 

contr

ol

&&

onl

y

 

r

un 

f

oll

ow i

ng

 

comma

nd 

i

f

 

pr

e

vi

ous

comma

nd 

compl

e

te

d

 

succe

ssf

ul

l

y

|

|

onl

y

 

r

un 

f

oll

ow i

ng

 

comma

nd 

i

f

 

pr

e

vi

ous

comma

nd 

f

a

i

l

e

d

´

encl

ose

 

str

i

ng

 

to be

 

ta

k

e

l

i

te

r

a

l

l

y

"

encl

ose

 

str

i

ng

 

to h

a

ve va

r

ia

bl

e

,

 

c

omma

nd

a

nd a

r

i

thme

ti

c substitution onl

y

$

(

 

)

i

n-

l

i

ne 

comma

nd 

s ubstitution 

(

new  

sty

l

e

)

`

i

n-

l

i

ne 

comma

nd 

s ubstitution 

(

old sty

l

e

)

(

(

.

.

.

)

)

a

rith

me

ti

c eva

l

ua

tion,

 

li

k

ele

"

.

.

.

"

$

(

(

.

.

.

)

)

i

n-

l

i

ne a

r

i

thme

ti

c eva

l

ua

tion

\

tr

e

a

t f

oll

ow i

ng

 

c

h

a

r

a

c

te

r

 

l

i

te

r

a

l

l

y

\new line

l

i

ne 

continua

ti

on

SPECI

AL 

CH A RA CTERS

Jobs ca

n be repre

se

nted a

f

ol

l

ow s:

j

obi

d

the 

j

ob 

i

dentif

i

e

r

 

f

o

r

 

a

 

j

ob,

 

w h

er

e

:

%%

cur

r

ent j

ob

%+

cur

r

ent j

ob

pr

e

vi

ous 

j

ob

%?str

j

ob uni

que

l

y

 

i

dentif

ied bystr

%n

j

ob numbern

%pr

e

f

j

ob 

w h

ose comma

nd 

l

i

ne beg

i

ns

w ithpr

e

f

Us ua

ll

y

,aproce

ss I

D   ma

y

 

be use

i

ns te

a

d

 

of

 

aj

obi

d.

Comma

nds th

a

t ta

k

e

 

aj

obi

dus e

 

the 

cur

r

ent

 

j

ob 

i

f

 no

j

obi

di

s suppl

i

ed.

Tra

ps   on SI

G CH LD e

x

e

cute

 

w h

e

neve

r

 

a

 

j

ob 

compl

e

te

s.

Th

e

 

comma

nds f

ga

ndbga

re only

 

a

va

i

l

a

ble

 

on s y

ste

ms

th

a

t support j

ob contr

ol

.Th

i

s i

ncl

ude

s Li

nux

,

 BSD

sy

ste

ms,

 

Sy

ste

V Rel

e

a

se

 

4,

 

a

nd 

most 

UNI

X sy

ste

ms.

JOB 

I

DS A N D 

JOB CONTROL

24

background image

Th

er

e

a

dli

nel

i

br

a

ry

 

i

mpl

e

ments comma

nd 

l

i

ne editi

ng

.

By

 def

a

ult,

 

it provi

des a

n e

ma

c

s editi

ng

 i

nte

r

f

a

c

e

,

a

lthoug

h

 a vi i

nte

r

f

a

c

e

 i

s a

va

i

la

bl

e.r

e

a

dline i

s

i

niti

a

li

zed e

ith

er

 

f

r

om 

the 

f

i

l

e na

med by$

I

NPUTRC (

i

f

se

t)

,

 or from ˜

/

.

inputrc.I

n th

a

t f

i

l

e

,

 y

ou ca

n use

conditi

ona

l

s,

 de

f

ine k

ey

 bi

ndi

ng

s for ma

cros a

nd

f

unc

ti

ons,

 

a

nd se

t va

ri

a

bl

e

s.

From 

theba

shleve

l,

 

thebindcomma

nd a

l

low s 

y

ou 

to

add,

 

r

emove a

nd chang

e

 ma

cro a

nd k

ey

 bi

ndi

ng

s.

Th

er

e

 

a

r

e

 

fi

ve 

i

nput 

mode

 

ma

p na

me

th

a

t c

ontr

ol the

a

ction 

ta

k

e

f

or e

a

c

h

 

i

nput c

h

a

r

a

c

te

r.

Th

e

 

ma

p na

mes

a

r

ee

ma

c

s,e

ma

c

s-

sta

ndard,e

ma

c

s-

me

ta

,ema

c

s-

c

tlx,

vi,vi

-

comma

nd,

a

ndvi

-

i

nsert.e

ma

c

s i

s the 

sa

me

 

a

s

e

ma

c

s-

sta

ndard,

a

ndvii

s the 

sa

me

 

a

s vi

-

comma

nd.

Youchoos e

 

w hi

ch editor 

y

ou pr

e

f

e

r

 

w ith

or

i

y

our˜

/

.

ba

sh

rcf

i

l

e

,

 

or a

t ru

nti

me.

r

e

a

dlineundersta

nds th

e

 

c

h

a

racter na

mes DEL,ESC,

LFD,

NEW LI

NE,

RET,

RETURN,

RUBOUT,

SP

A CE,

SP

C a

nd

TA B.

REA DLI

NE

Dir

e

ctive

i

the.

inputrc f

i

l

e provi

de 

conditi

ona

a

nd

i

nclude

 

f

a

ci

l

i

tie

s si

mi

l

a

r to the 

C preproce

ssor

.

$

include

i

ncl

ude

 

a

 f

i

l

e

,

 

e

.

g

.

,

 

a

 

sy

ste

m-

w i

de/

e

tc/

inputrcf

i

le

$

if

sta

r

t a conditi

ona

l,

 

f

or te

rmi

na

l or

 a

ppl

i

ca

tion

speci

f

ic se

tti

ng

s.

Youca

te

st the 

f

oll

ow i

ng

:

a

pplica

tion= te

st th

e

 

a

ppl

i

ca

tion,

 

e

.

g

.

ba

shorgdb

mode=

te

st the editi

ng

 

mode,

e

ma

c

s orvi

te

rm=

te

st the 

te

rmi

na

l ty

pe

The use ofa

pplica

tion=i

s optiona

l;

 

e

.

g

.

,

$

i

f

 

Ba

sh

$

else

sta

r

tthe 

e

l

se

’pa

r

 

tof

 

a conditi

ona

l

$

endif

f

i

ni

s h

 

a

 

conditi

ona

l

REA DLI

NE 

DI

RECTI

VES

Ke

y

s   bound 

to a

 

ma

cro pl

a

c

e

 

the 

ma

cro te

x

i

nto the

i

nput;

 

k

e

y

s   bound 

to a

 

f

unc

ti

on 

r

un 

the 

f

unc

ti

on.

Youca

n use

 

th

ese

 

e

sca

pe 

se

quences 

i

n bi

ndi

ng

s:

\

a

a

le

r

t(

be

l

l

)

\

r

ca

r

r

i

a

g

e

 

r

e

tur

n

\

b

ba

ck

spa

ce

\

t

h

oriz

onta

l tab 

(

TA B)

contr

ol

 

pr

e

f

ix

\

v

verti

c

a

lta

b

\

d

del

e

te

 

(

DEL)

\

\

ba

ck

sl

a

sh

\

e

e

sca

pe 

(

ESC)

\

"

l

i

ter

a

l"

\

f

f

or

f

e

e

d

\

´

l

i

ter

a

me

ta

 

pre

fi

x

\

ddd

octa

l

 

va

l

ueddd

\

n

new l

i

ne

\

xh

h

h

h

e

x

 

va

l

ueh

h

h

Ma

cr

os a

nd 

f

unc

ti

on bi

ndi

ng

look

 

l

i

k

e

:

ma

cro:

k

e

y

-

se

q

:

"

te

x

t

"

f

unc

ti

on:

k

e

y

-

se

q

:

f

unc

tio

n-

na

me

Ma

cros h

a

ve quote

d

 

te

x

t on th

e

 

ri

g

ht of the 

col

on;

f

unc

ti

ons   h

a

ve f

unc

ti

on na

me

s.A k

e

y

-

se

q i

s e

ith

e

r

 

a

si

ng

l

e

 

ch

a

r

a

c

ter or ch

a

r

a

c

te

r

 

na

me

 

(

s uch

 

a

s

)

,

or a

 

quote

d

 

stri

ng

 of

 

c

h

a

r

a

c

te

r

s (

si

ng

l

e

 

or

 doubl

e

quote

s)

.

REA DLI

NE 

KEY BI

N DI

N G S

25

Va

r

ia

bl

e

s contr

ol di

f

f

e

r

ent a

spects of r

e

a

dline

s

b

e

h

a

vi

or

.

You s et a

 

v

a

ri

a

ble

 

w ith

se

tva

r

i

a

bl

e va

l

ue

Unl

e

ss oth

er

w i

se

 

noted,

va

l

ues h

oul

d be

 

eith

e

rOn or

Of

f

.

Th

e

 

descr

iptions   be

low  

descr

ibe 

th

e

 

ef

f

e

ct 

w hen

th

e

 

va

r

ia

bl

e

 i

s On.De

f

a

ult va

l

ues a

re sh

ow n i

n

pa

renth

e

se

s.

bell-

style(

audible)

def

i

nes   how r

e

a

dlines h

oul

r

ing

 

the bel

l

:

audible

r

ing

 

the bell

none

neve

r

 

r

i

ng

 

the bell

visible

f

la

sh 

the 

scr

e

e

n

comment-

beg

in (

#

)

i

ns e

r

t thi

s str

i

ng

 f

or r

e

a

dline-

i

nse

rt-

comment,

(

bound 

toM-

#i

n e

ma

c

s mode

 

a

nd 

to#

i

n vimode

)

comple

tion-

i

gnore

-

c

a

se(

Of

f

)

i

g

nore ca

se

 

w hen doi

ng

 

compl

e

ti

ons

comple

tion-

que

ry-

i

te

ms (

1

0

0

)

i

f

 

the number of compl

e

ti

on 

ite

ms 

i

l

e

ss 

th

a

thi

s

va

l

ue,

 

pl

a

c

e

 

th

em 

i

the 

comma

nd 

l

i

ne.

 

Oth

er

w i

se

,

a

sk

 

the use

r

 

i

f

 

th

ey

 

s h

ould be

 

sh

ow n

conve

rt-

me

ta(

On)

tr

e

a

t c

h

a

r

a

c

te

r

w ith 

th

e

 

ei

g

hth

 

bit 

se

a

the 

me

ta

ve

rsi

on of

 

the equi

va

l

ent seve

n bit 

c

h

a

r

a

cte

r

disa

b

le

-

comple

tion (

Of

f

)

do not 

do 

compl

e

tion

editing-

mode(

e

ma

c

s)

se

t the i

niti

a

l

 editi

ng

 mode.

 

Possi

bl

e va

lues a

r

e

ema

c

s orvi

ena

ble

-

k

eypad(

Of

f

)

a

tte

mpt to e

na

bl

e

 

th

e

 

a

ppli

ca

tion k

ey

pad.

Th

i

ma

y

be needed 

to 

ma

k

e

 

th

e

 

a

r

r

ow  

k

e

y

w ork

e

x

pa

nd-

tilde(

Of

f

)

a

tte

mpt ti

l

de expansi

on a

s   pa

r

tofw ord compl

e

tion

input-

me

ta(

Of

f

)

me

ta

-

f

la

g(

Of

f

)

ena

bl

e

 

ei

g

h

bit i

nput.

The 

tw o va

r

ia

bl

e na

me

s a

r

e

sy

nony

ms

k

ey

ma

p(

e

ma

c

s)

se

t the 

cur

r

ent k

e

y

ma

p.

 

Se

eRe

a

dl

i

nef

or a

 

l

i

st 

of

a

ll

ow ed va

l

ues.Th

e editing-

mode va

r

ia

bl

e a

lso

a

f

f

e

cts th

e

 

k

ey

ma

p

ma

rk

-

dir

e

ctorie

s (

On)

a

ppend 

a/

to compl

e

ted dir

e

ctory

 

na

mes

ma

rk

-

modi

f

ied-

lines (

Of

f

)

pl

a

c

e

 

a*a

t the 

f

r

ont of modi

f

ied h

i

story

 

li

nes

output

-

me

ta(

Of

f

)

pr

int c

h

a

r

a

c

te

r

w ith 

th

e

 

ei

g

hth

 

bit 

se

dir

e

ctly

,

not

a

s M-

x

print-

comple

tions -

h

orizonta

lly(

Of

f

)

di

s pl

a

y

 

compl

e

ti

ons   h

oriz

onta

ll

y

,w ith 

the 

ma

tch

e

s

sor

te

da

l

phabe

tica

l

l

y

,

i

nste

a

d of

 

ve

r

ti

ca

l

l

y

 

dow n 

the

scr

e

e

n

sh

ow -

a

ll-

i

f

-

a

mbig

uous (

Of

f

)

i

mmedi

a

te

l

y

 l

i

st w ords w ith multi

pl

e possi

bl

e

compl

e

ti

ons,

 

i

ns te

a

d of

 

ri

ng

i

ng

 

the bel

l

visible

-

sta

ts (

Of

f

)

w hen li

sti

ng

 

possi

bl

e compl

e

ti

ons,

 a

ppend a

c

h

a

r

a

c

te

r

 

th

a

denote

s the 

f

i

l

e

s ty

pe

REA DLI

NE 

VA RI

A BLES

Mor

e

 

i

nf

orma

ti

on aboutr

e

a

dli

neca

n be

 

f

ound on-

l

i

ne

 

a

t

http:

/

/

w w w .

ssc

.

c

om/

ssc/

ba

sh

.

26