You are on page 1of 7

BA SH REFERENCE DEFI

NITI
ONS COMMA ND LI
NEA RGUMEN TS INVOCATI ON A ND STA RTUP( continued)
Thi
s ca
rdde
scri
bes version 2.
02.
0ofbash. bash acce pts the one le
tter options to set,and the 3.I nvok ed a s sh:I nteracti
ve login s hells read and
CONTENTS Seve raltypefaces areusedtocla rifythemea ni
ng: additionaloneletterandG N U-
sty lelongoptions show n execute/ etc/profileand˜ /
.profileiftheyex ist.Th ese
A liasing. ..
..
..........
.
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.6 • SerifaBoldi s usedf orcompute rinput. below . fi
les a re skipped i f i
s us ed.I nteractive
A rithme ticEva luation...
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.8 • Serif
aI ta
lc is used to i
i ndica te u ser input a
nd f
or shells expand $ EN V a nd executetha tfi leifit e xists.
$ba options][
sh[ arg
s]
Ar ra ys...
..
...
..
. ...
. .
. .
.
...
..
...
..
.
..
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.13 synta c
ticplace holders,sucha s va r
ia eorcmd.
bl Non- interactive sh ells do not rea d any sta rtup f iles.
ends option pr oce ssi ng
BraceExpansi on. .
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.6 • Serif
aRoman is usedf ore xplana toryte x
t. Afterthesta rtupf iles a reexecuted, bashente rsP OSI X
ends option pr oce ssi ng
Bui lt-In Commands . ..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.16 mode.
blank cmd execute cmd ( de fault r eads
CommandLi neA r guments .
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.3 command f rom f ile named i n 4.POSI X mode:W hen startedw ith ,
inte
ractive
CommandSubstitution. ..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.8 or more spaces and/or tab characters.I
n addition,
w ords a re te
rmi
na ted by a ny of the follow i
ng first entryofa rg s andf oundvi a shells expand $EN V and execute the gi
ven fi
le.N o
Conditi ona lExpressi ons .
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.15 pa ths ea rch) otherstartupfilesareread.
Contr olCommands . ..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.14 chara c
ters:
;&()|<>spacetabnew line pr int a lldouble quote dstri ngs
Def initions...........
.
...
..
...
..
.
..
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.2 5. Invokedviarshd:I frun from rshdandnotinvok eda s
tha ta re preceded by a $to
ExecutionOr der. .
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.13 comma
nd w ords. sh, bashreads ˜
/.
bash rc. The option ski
ps this
stdout.This i mpli es ,no
FieldSpli tti
ng. ....
.
....
..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.8 ste p,andthe option changes thef i
le,butrshd
l
ist pi
pel
ines.Can be separatedby;
,&, commands a reexecuted
Functions . .
..........
.
...
..
...
..
.
..
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.12 us uallydoes not pass theseoptions on to thesh ellit
&&, |andoptiona
| llybeterminatedby;,&. se tinte ra ctivemode
H istor ySubstitution. ...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.5 invok es.
se tr estri ctedmode
Input/ Output. .....
.
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.13 n
read commands f rom stdin If$SH ELLOPTS exists i
n theenvir
onment a
t star
tup,
Invoca tion andSta rtup...
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.3 na
me (def ault) bashenables thegi
venoptions.
JobI ds andJobContr ol.
..
.
..
..
..
.
..
.
..
..
.
..
..
.
..
..
.
..
.
..
..
.24 sa mea s , butoutput i n GNU
Options Toset. ...
.
...
..
...
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.22 key
wo rd bash language.
Keyw ords are special onlyaf
tera;or new line,a f
ter g ettextf orma t
Options Tos hopt. ...
..
...
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.23 sa mea s PROMPTI
NG
Options Tote st. ..
.
...
..
...
..
.
..
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.21 anotherk ey
w ord,a ndincertai
n otherconte
xts. W hen inte r
a c
tive,ba sh dis pla
ys the prima
ry and
di s pla yah elpmessa geandexi t
Pa tterns...
...
..
... .
. .
...
...
..
...
..
.
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
..
.9 p
a t bashpattern.
SeePa
tter
ns. successf ully secondary prompt stri ngs,$ PS1 and $PS2.bash
Pre -Def inedVa riables .
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.10 a ctlik ealog in s hell expands thef ollow i
ngescapesequences i
n thevalues
Proce ss Substitution . ..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.8 pi
pel
ine
do not us etherea dlineli bra ry ofthesestrings.
Prompting. .
.........
.
....
..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.4 byapipe(
|)
.
to re a d commands \w hen
a an A SCI IBELcha racter( octa l0 7)
Quoting. ..
..
..........
.
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.6 stri
ng inte ra cti ve
Rea dline. .
...
.........
.
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.25 \d theda tei n‘ ‘
W eek dayMonthDa y ’
’forma t
substitution do not r ea d any of the \e an A SCI Iesca pechar acter( octal033)
Rea dlineDir ectives . ..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.25 command li ne w ith di
fferent text,e .
g.
,r epla
cing a initia li
za tion fil
es. Se e
Rea dlineKeyBi ndings ..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.25 \h thehostna meuptothef irstdot( .)
va riable w ith its va lue. ba sh per forms many Invoca tionAndSta rtup, below\H thef ullhostname
Rea dlineVa riables . ..
..
..
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.26 s ubstitutions.
This cardlists them in theordertheyare do not r ea d ˜ /.ba sh rc i f
Restri ctedba sh. ..
.
...
..
...
..
.
..
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.2 \n anew li ne
per formed. inte ra cti ve.SeeI nvoca tion And
\r aca rria g er eturn
Signals a ndTraps . ..
..
...
..
.
..
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.13 Sta rtup, below
Specia lCha ra cte rs.
..
...
...
..
..
.
..
..
.
..
..
..
.
..
..
.
..
..
.
..
..
.
..
..
.24 word \s thena meofthesh ell(basena meof$ 0 )
necessa
ryi
fitconta
ins speci
a lcharacters. follow the I EEE POSIX 1 \0
t 03.2 thetimei n 24- hourH H :MM: SS forma t
TildeSubstitution. ..
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
..
.
..
.6 sta nda r d
Va riableAssi gnment. ..
..
.
..
..
..
.
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.9 \T thetimei n1 2- hourH H :MM: SS forma t
fi
le use f i
lei ns te ad of˜ /.ba sh
\urc if theuser ’s user name
Va riableNames . .
.
...
..
...
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.9 RESTRI
CTED bash inte ra cti ve \v theversi onofba sh( e.g.,2.0 2)
Va riableSubstitution . .
..
..
.
..
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.
..
.
..
..
.7 I
fbashis i nvok eda s rbash, orw iththe option, itis sa mea s \V theversi onandpatc hleve lofba sh( e
.g., 2.02.0)
r
estri
cted.Thef ollow inga ctions are not a
llow ed in a sa mea s
This ref
erencecar
dw a s w ritten byA rnoldRobbi ns.We \w thecur rentw ork ingdir ectory
r
estrictedsh ell: pr int versi on i nf orma tion on
thankChe tRa mey(bash’s ma intai
ner
)f orhi
sh elp. \W thebasena meofthecur rentw ork ingdir ectory
chang ingdir ectoryw ithcd stdouta ndexitsucce ssf ully
\! thehi storynumberofthi s command
setti
ngorunse tting$ SH ELL or$ PATH \# thecommandnumberofthi s command
OTHER SSC PRODUCTS: usingpa thna me sforcommands thatconta i
n/ INVOCATI ON A ND S TA RTUP \$ a#i ftheef f
ectiveUI Di s0 , other wi sea$
usingapa thna metha tconta i
ns / forthe. command Ther ea ref ivew a ys th atba shr uns:nor ma linte r
a c ve, \
ti @ thetimei n1 2- houra m/ pm f orma t
SpecializedSystems Cons ulta nts,I
nc. importingf unctions from theenvir onment nor ma l non- interactive,a s sh,i n POSIX mode,or \ \ aba ck slash
(
20 6)FOR- UNIX/(206)782-7733 parsing$ SH ELLOPTS a tstartup invok edvi arshd. \nnn thecharactercorrespondi ngtoocta lva luennn
FAX:(206)782-7191 redir
e ctingoutputw ithanyof>, >|, <>, >&,&>,or>> \[ startasequenceofnon- printingcha racters
usingexectorun adi ff
erent command 1 .Nor ma li nteractive:Log in s hells run commands i n \] endasequenceofnon- printingchar acters
E- mai
l:sal
es@ ssc.com addingordele tingbuilt- i
ncommands w ithena ble /etc/profile.Thef irst of˜/.bash _profile,˜/.bash _login,
URL:h ttp:
//
w w w.
ssc.com and ˜ /profiletha
. tis found i s e xe cute d.Thi s stag eis Theh istorynumberis thenumberofthecommandi n
using toby pass ar estricted$PATH
sk i
ppedi f i
s us ed. thehistoryli st,w hichma yi ncludecommands restore d
usingse t+ rorset+ orestricted
from the hi story f il
e.The command number is the
Upon logout, ba shr uns ˜/.
ba sh_ logouti fite x i
sts.
LinuxJourna l—ThePre mi erLinuxMaga zine These r estricti ons are i n ef f
ect a f
ter executing a ll number of thi s command sta rting f rom the f irst
Technica lBook s andCDs startupf i
les, a llow i
ngtheauthorofthesta rtupfiles f
ull Inte r
a c
tive non- login s hells e xecute ˜ /.ba shrc,if i t commandr un bythecur r
entinvoca tion ofthesh ell.
control in setting up the r estri
cted environment.( I
n ex i
sts.The i
f eoption chang
il e s thef i
leth atis
SA MBA :Integr
a tingUNIX a ndW indow s Thedef aultva lueofPS1i s‘‘ ’
’.
practice,r estri cted shells are not usedmuch ,a s they us ed.
ShellTutoria ls,KSH Ref erence aredi f
ficulttosetupcor rectly.
)
2.Nor mal non- inte r
a c
tive:Non- i
nte
ractive sh ells do
VI&Emacs Ref erences, VITutor
ial var
iable,command,and a rithmeticsubstitution on the
Er
rorRepor
ting va
lue of $ BA SH _ENV,and i f the result na mes a n
Ifyouf inda n er
r orin this ref
erenceanda rethefirstto exi
sti
ngf i
le,tha tfileise xecuted.
© Copyr ight1 999Speci ali
zedSystems Cons ultants,I
nc.
, report it,w ew illsend y ou afreecopyofanyofour
P.O. Box55549 ,Seattle,
WA9 81
55- 0549. references.Plea se w rite,or s end electr
onic ma il to
A llRights Reserved. bugs@ssc. com.
1 2 3 4
HI
STORY SUBSTI
TUTI
ON QUOTI
NG VA RI
A BLESUBSTI
TUTI
ON A RI
TH METI
C EVALUATI
ON
H istoryexpansion is simi la
r to csh’ s.Itis enabled by \c quotesinglecha racterc $
na me referencetosh ellva r
iablena me A rithmetic eva
luation is done w ith the let built-
in
def ault in i nteracti
ve sh ells. H istory ex pansion .
`.
.̀ olds ty lecommands ubstitution ${name} us ebraces todeli mitsh ellva r
iablena me command, the ( (.
..
)) command and the $ (
(..
.
))
happens bef oreth esh ellbreak s theinputinto w ords, ".
..
" tex ttr eateda s asinglea r
gument, double ${name w o rd} ex pansi
onf orproducingther esultofan expression.
although quoti ng is recognized and quote d te xt is quotes re moved;va riable, commandand us eva ria blena mei fset, elseusew o rd
A llarithme ticuses longintege rs. Use to get
trea tedas oneh i
story‘‘w ord’’
. arithme ti
csubstitutions per formed; ${name=w o rd}
integ er variables.Integer consta nts looklike[
ba #
se ]n
use\toquote$ ,\, ,
`and" a sa bovebuta lsosetna metow o r
d
H istory s ubstitution i s per f
ormed on history eve nts, w her eba sei s adecimalnumberbetw een tw o a nd 64,
$ " ..
." li
k e" ...",
butloca letranslation done ${name?w o r d}
w hi chcons istofa n eve ntde si
g nator(w hi chprevi ous li
ne andn i sin tha tbase.Thedi gits are0 -9,a-z,
A-Z, _and
´...́ tex ttr eateda s asinglea r
gument, si
ngle usena mei fset, oth e rw i sepr intw o rdand
tosta rtw ith),aw ordde signator( w hichw ordfrom th at @. A leading0or0 xdenoteocta lorh exadeci
mal.
quote s re
moved;tex tbetw een quotes ex it( inte ractivesh ells donote x it)
line to use ,sta rting w ith zero), a nd one or more
lefta lone,cannoti nclude´ ${name+w o rd} The follow i
ng oper
a tors based on C,w ith the sa
me
optiona lmodi f
ie s (
r w hich pa rts ofthe w ords to use )
.
$́. ..́ tex ttr eateda s asinglea r
gument, $and usew o rdi fna meis se t, otherw iseuse precedenceandassoci ativity
,areavai
lable.
Colons sepa rate the three parts,a lthough the colon
singlequote s removed;nos ubstitutions nothi ng
betw een the event designa tor a nd w ord desi gna tor una ryplus andmi nus
per formed;A N SIC andadditiona l $
{na me[
n]} elementni n ar r
a yna me
ma ybeomittedw hen thew orddesi gna torbeg ins w ith !˜ log i
ca landbitw isenegation
esca pesequences processed: $
{# name} leng thofshellva ria blena me
ˆ, $,* ,, or%. Eachmodi fieris sepa ra tedfrom thenext ** exponentia ti
on (notin C)
$
{# name[*]} numberofe lements i n ar r
a yna me
onew ithacolon.Thehistchars va riablespeci fies the \ a a lert( bell) \ v verticalta b */ % multiply ,di vi
de, modulus
$
{# name[@]} numberofe lements i n ar r
a yna me
sta rt-of-
historyand qui cksubstitution cha racters,a nd \ b back spa ce \ddd octalva lueddd addition, subtraction
$
{na me#pat} re movesh orte stleadings ubstr i
ng
a lsothecomment cha ra ctertha tindi ca te s tha ttherest \ f f ormf eed \ xh hh hexva lueh hh << >> lefts hif
t, rightshi ft
ofna methatma tch e sp at
ofali nei s acomment.Theprevi ous command i s the \ n new li ne \\ back slash < <= > >= compa r
isons
$
{na me## p
a t} re movelong estlea di ngs ubstr ing
def a ulteventifnoeve ntdesi gna toris suppli ed. \ r ca rr
iager eturn \ e esca pe, notin A N SIC == != equals, not equa ls
ofna methatma tch e sp at
\ t horiz onta ltab & bitw iseA N D
Theeventdesi gna tors a re: $
{na me%p at} re movesh ortesttra ilings ubstr ing
ˆ bitw iseXOR
! sta rtahi storys ubstitution ofna methatma tch e sp at
ALI A SI NG | bitw iseOR
!n commandli nen $
{na me%%p a t}
a lia s name =va lue. .
. && log i
ca lA N D, shortcir cuit
n cur rentlineminus n ( n previ ous) re movelong esttra ilings ubstr ing
|| log i
ca lOR, shortcir cuit
!! theprevi ous command A lia ses a re expanded w hen acommand i s read,not ofna methatma tch e sp at
?: in-li
neconditiona l
!str most r ecent command li nesta rtingw ith w hen execute d.A lias na mes ca n conta i
n any non- $
{na me:
start}
str speci alchar acte r,notj us t a lphanume rics,ex ceptf or=. $
{na me:
start: l
eng th }
a
ssignmentopera
tors
!?str[?] mostrece ntcommandli neconta i
ni ngstr A lia s ex pansi on i s doneon thef irstw o rdofacommand. leng thcharacters ofna mesta rtinga t
!# theentir ecommandlinety pedsof ar Ifthela st cha racterofth ereplace menttex tis abl a nk, sta rt( countingf r om 0 );us erestof Insi
delet,(
(.
..)
),and$ (
(.
..
)
),va
riablenames donotneed
ˆoldn̂ew ˆ qui cksubstitution:r epeatla st command then thenextw ordi n thecommandlineis check edf or va luei fnol ength . N egativesta rt a$ togettheirvalues.
chang ingol dtonew a lias ex pansion.A li ases ca n even beused to rede fine counts f rom theend. Ifna mei s *or@
sh ellk ey w ords , butnotin POSI X mode. ora na rra yi ndexedby*or@, sta rt COMMA ND SUBSTI
TUTI
ON
Thew orddesi gna tors a re:
andl eng thindi ca tethea rrayindexa nd $(
command) new form
0 thezero’ thw ord( command na me)
countofelements. sta rtandl eng thcan `
command` oldf orm
n w ordn BRA CEEXP A NSI ON bea rithme ticex pressi ons
ˆ thef irsta rg ument, i.
e., w or done Brace expansion i s si mi lar to csh’ s.A w ord must Run comma nd,s ubstitute the r esults a s arguments.
$
{na me/patte rn/ stri ng }
$ thela sta rgument conta in atlea st oneunquotedleftbraceandcommato Traili
ng new lines a re removed.Cha racters i
n $ IFS
va lueofna mew ithf irstma tchofpa tte
rn
% the w ord ma tched by the most rece nt be expanded.ba sh expands the comma -separate d separ atew ords (seeFi eld Spli
tti
ng )
.Thenew f orm is
replace dw ithstr ing
!?str ?se a rch items i n or der ,the result is not sorted. Brace preferredforsimplerquotingr ules.
$
{na me/patte rn}
xy w or ds xthrou ghy . i s shortf or ex pansi ons ma ybenested. Forexa mple: va lueofna mew ithf irstma tchofpa tte
rn $
((
expr
essi )a
on) rithme
ticsubstitution
* w ords 1 throughth elast( like )
$ mk dir/ usr/ {gnu,loca l}/{src,bin, lib} dele te d
n* w or ds nthrou ghth elast( liken ) Theex
pressi s eva
oni luated,a ndtheresultis useda
san
$
{na me//patte rn/ stri ng }
n w or ds nthrou ghthenexttola st arg
umenttothecurre nt command.
va lueofna mew ithever yma tchof
Themodi f
iers are: TI
LDE SUBSTI
TUTI
ON pa tte rn replace dw ithstri ng
e removea llbutthes uf fi
xofaf i
lename ˜ s ubstitute$ H OME $
{na me/#pa ttern/ stri ng } PROCESS SUBSTI
TUTI
ON
g ma k e chang es globally , us e w ith s ũs e
r s ubstituteuse r’
shomedir ectory va lueofna mew ithma tchofpa tte r
n cmd<(
li )>(
st1 li
st2)
modi fier
, below ˜
+ s ubstitute$ PW D replace dw ithstr ing ;ma tchmus toccur
h remove the la st part of a f i
lename, s ubstitute$ OLD PW D a tbegi nning Runs l st1and l
i st2 a
i sy nchronous ly,w ith stdin and
leavingthe‘ ‘head’ ’ ñ s ubstitute$ {DIRSTA CK[n]}.A lea ding+ $
{na me/%pa tter n/ stri ng } stdout respecti velyconnectedviapi pes usingfif
os or
p printthecommandbutdonot e xe
cutei t or i s a llow ed:negative va lues count va lueofna mew ithma tchofpa tte r
n files i
n/ dev/fd. Th esefilena mes becomea rguments to
q quoteth eg e
nera tedtext from theendofthestack replace dw ithstr ing ;ma tchoccurs a t end cmd, w hichexpects toreadits firsta rgument a ndw rite
r removethela stsuf f
ixofaf il
ena me its second. This onlyw ork si
fyouh a ve/ dev/fdorfifos.
Tildes ubstitution happens af
tera li
a s expansi
on.I tis Note :for ,=,?,and + ,usingna me:inste
a d ofna
me
s/ d/
ol new / s ubstitutenew f oroldi n the tex t.A ny done f or w ords tha t begi
n w ith ˜and f or va
riable te
sts w hetherna meis set a nd non-
NULL;usi ngname
delimiter ma y be used.A n & i n the assignment. tests onlyw hetherna
mei s se
t.
FI
ELD SPLI
TTI
NG
replace mentmeans theva lueofold. W ith Quoted te x t becomes one w ord. Other wi se,
emptyol d, usela stol
d,orthemostr ecent In var
iableassi gnments,itis a lsodoneaf tera:in the For# ,# #,%, %%, /,/,
//,
#and/ %,w hen nameis *or@ occurrences ofa nychar acteri n$ IFS sepa r
a tew ords.
!?str
?se a rchi ftherew a s no previous old value.Ti lde s ubstitution is done as pa rt of w ord or a n a rrayi ndexed by * or @,the s ubstring or Multiplew hitespa cecha racters tha tarein$ IFS donot
t removea llbutthela stpa rtofaf i
lename, expansion. Th i
s mea ns f
or$ {nameopw o d},
r wordw illbe s ubstitutionoperati
onisappli
edtoe achelement. deli
mit emptyw ords,w hi le multiple non- w hitespace
leavingthe‘ ‘ta il’
’ checkedf ortildes ubstitution, but onlyi
ftheoper ation characters do.W hen $ IFS is not the def ault va lue,
x quoteth eg eneratedte xt,but bre aki nto requir
es theva lueofther ight-handsi de. sequences of lea di
ng and tr aili
ng $ IFS w hite spa ce
w ords atbl ank s andnew line characters a re removed,and pr intable cha racters i n
& repea tth elastsubstitution $IFS s ur rounded by adj ace nt $ IFS w hite spa ce
characters delimit f
ields.I f$ IFS i s NULL,ba shdoes
notdof ields pli
tti
ng.
5 6 7 8
PATTERNS PRE-
DEFI
NED VA RI
A BLES PRE-
DEFI
NED VA RI
A BLES (
continued) PRE-
DEFI
NED VA RI
A BLES (
cont
inued)
? matchsinglecharac
te rinfilena me $n usepositiona lpa ra me te rn, n 9 $
H ISTCMD history number of the cur r
ent $
OSTYPE string describing the
* match0ormorec h aracters in f
il
ename ${n} usepositiona lpa ra me te rn command oper ati
ng sy stem r unni ng
[
chas]
r matchanyofc har
s $* a llpositiona lpara me ters H ISTCONTROL w ithava
$ lue ofignore spa ce,do not bash
(
pairseparatedbya ma tch es arange
) $@ a llpositiona lpara me ters enter lines that begi n w ith s paces $
PATH commandse archpa th
[!c ha rs] matcha nyexceptcha r
s "$ *
" equi va lentto" $1 $ 2. .." into thehi storyf ile.W ithava lueof $
PIPESTATUS[
*] arra yva r
iable conta i
ningex i
t
[ĉh a rs] matcha nyexceptcha r
s "$@" equi va lentto" $1 "" $ 2". .
. ignore dups,do not e nte rali neth at status va lues from proce sses
$# numberofpositi ona lpa rameters ma tches the previ ous li ne. Use in themostr ecentlyexecuted
If the extglob option to s hopt i s set,the f ollow ing
options toshellorbyset ignore bothtocombi nebothoptions fore groundpi peline
ex tendedma tch i
ngf acilities ma ybeused.
$
? va luer e tur nedbyla stcommand $
H ISTFI LE w her ecommandhistor yi s store d $
PPI
D proce ss idofshell’ s parent
?( pa t-lst)
i optiona llyma tchanyofthepatterns $
$ proce ss numberofcurrentsh ell $
H ISTFI LESIZE ma ximum numbero flines to k eep i n $
PROMPT_
COMMA N D command to r un bef oree ach
*( pa t-lst)
i ma tc h0ormoreofanyofthepatterns $
! process number ofla st ba ck ground $ H ISTFI LE prima ryprompt
+( pa t
-lst)
i ma tch1 ormoreofanyofthepatterns cmd H ISTIG N ORE colon-
$ sepa ra tedli st ofpa tterns;i fthe $
PS1 prima ry prompt string
@( pa t-l
ist) ma tche x actly1 ofa nyofthepatterns $
_ name ofpr og ram i n envir onment a t cur rentlinema tches a nyofthem, the ( )
!( pa t-l
ist) ma tchany thingbut a nyofthepa tterns sta rtup. Va lue of la st positi ona l linei s not enteredi n thehi storyf i
le. $
PS2 seconda rypromptstri ng( >)
a rgumentin la st command. Nameof & represe nts th e la st hi story li ne. $
PS3 select command pr ompt
pa t- l
istis alistofoneormorepatterns separatedby| .
changedma ilf ilei n$ MA I LPATH Pa tterns mustma tchthew holeli ne string( #?)
ThePOSI X [ [=c=] ]and[ [.c.
]]nota tions forsa me- w eight $auto_ resume ena ble s use of single- w ord $
H ISTSIZE number of pr evi ous commands to $
PS4 tracingpromptstri ng( +)
char a cters a nd colla ting elements a re accepte d.The commands to ma tchs toppedj obs f or k eepava ilablew hileba shis running $
PW D cur rentw ork ingdir ectory
nota tion [[:class: ]]def ines cha ra ctercla sse s: fore g roundi ng. W ithava lueofexa ct, $
H OME homedir ectoryf orcd command and $
RA N DOM set e achti meit’ s referenced,
the w ord must exa ctly ma tch the va lueusedf orti ldeexpansi on
alnum a lphanumer ic low er low er -ca se
command use d tosta rtthej ob. W ith $
H OSTFILE filei nf orma t of/ etc/ hosts to usef or $
REPLY set by the se lect and read
alpha a lphabetic print printable
ava lueofs ubstring, thety pedw or d hostna mecomple tion commands
blank spaceorta b punct punctua tion
ca n beas ubstr ingofthecommand, $
H OSTNA ME na meofthecur r enthost $
S ECONDS numberofseconds si nces hell
cntrl control space w hite spa ce
lik e%?stri ng $
H OSTTYPE stri ngde scr ibi ngthecur renthost invoca tion
digit deci ma l upper upper -ca se
$
BA SH fullf ilena meusedtoi nvok ebash $
IFS fields epa ra tors ( space, ta b, new line) $
SH ELL na meofthi s shell
graph non- spaces xdigit hexadeci ma l
$
BA SH _ENV in norma lnon- inte ra cti ve sh ells only , $
IG N OREEOF f or inte r ac tive sh ells,the numberof $
SH ELLOPTS colon-se para ted list of the
Thr e es hoptoptions a ff ectpa tter n ma tch i
ng. va lue i s va riable, command and consecutive EOFs tha t must be ena bled sh ell options forset
a rithme tic substituted f or pa th of enteredbe for ebasha ctua llyex its
dotg lob includef iles w hosena mes begi n w ith.
sta rtup f ile ( Se e I nvoca tion And $
INPUTRC na me of rea dline sta rtup f i
le, $
SH LVL incre
mented byone f orea ch
nocase glob ignoreca sew hen ma tch i
ng
Sta rtup) over r
ides ˜ / .
inputrc s ub-
bash
nullglob re movepa tterns thatdon’tma tch
$
BA SH _VERSION theversi onofba sh $
LANG na meofc ur r entloca le $
TIMEFORMA T format string f or output of
W hen expandi ng f i
lena me s,.and . .a re ignored, $ BA SH _VERSINFO[ 0 ] the ma j
or version number $
LC_ALL cur rentloca le;overri des $ LANG and time keyw ord. Speci al
filena me s ma tch i
ngthepatterns i n$ G LOBIG N OREa r
e (relea se ) oth er$ LC_va riables constructs i
ntroducedby%.
also i gnored a ndalea di ng. must be s uppli ed i n the $BA SH _VERSINFO[ 1 ] the mi nor versi on number LC_COLLATE cur
$ rentloca lef or ch aractercolla tion, p]
%[ [
l]R elapsedsecs
pa ttern to ma tch f ilena me s tha t begin w ith .. ( ve rsi on) includes sorti ng results off ilena me p]
%[ [
l]U userCPU secs
H ow eve r,setting G LOBIG N ORE ena bles thedotg lob $BA SH _VERSINFO[ 2] thepatchlevel ex pansion p]
%[ [
l]S sy stem C PU secs
option. I
nclude. *i n G LOBIG N ORE to g et th ede f
ault $BA SH _VERSINFO[ 3] thebuildversi on $
LC_CTYPE cur rent loca le f or ch aracter cla ss %P CPU percenta ge
behavi or . $
BA SH _VERSINFO[ 4] there lea sesta tus functi ons ( seePa tter ns) %% literal%
$
BA SH _VERSINFO[ 5] sa mea s$ MA CH TYPE LC_MESSA G ES cur
$ rent loca le f or tra nsla ting $ "..."
VA RI A BLEN A MES $
CDPATH se a rc hpa thforcdcommand stri ngs Optiona lpgi ves thepr eci
sion,
Va riable na mes a re made up of le tters,d i
gits a nd $DIRSTA CK[ *] a rra y va riable conta i ni ng the pus hd $
LINENO linenumberoflinebei ngexecutedi n thenumberofdig its afterthe
underscore s. Theyma ynot sta rtw ithadigit. Therei s andpopddir ectorystack scr iptorf uncti on decima l poi nt; it mus t be
no li miton theleng thofava r iablename, andthec ase $EN V in i nte r a c tive POSIX modesh ells,or $
MA CH TYPE astri ng in G N U cpu- compa ny-sy ste m betw een 0a nd 3.Optiona ll
ofle tte rsis signi f
ica nt. w hen i nvok eda s sh, va luei s va r
ia ble, for ma t de scri bing the ma chi ne produces along er forma t,in
commandandarithmeticsubstituted runni ngbash theform MMmSS. FFs
forpa thofsta rtupf i
le $
MA I L na meofama ilf il
e, i
fany $
TMOUT number of seconds to w a i
t
VA RI A BLEASSI G N MEN T $
EUI D theef fectiveuserid( rea donly ) $
MA I LCHECK checkf or ma il eve r y n seconds ( 60 during prompt before
A ssignments to inte g er va riables underg oa rithme ti
c termina ting
$
FCED I T def aulteditorforthef ccommand( no def ault)
eva luation.Va ria ble a ssignments h a ve one of the $
UID ther ealuserid( readonly )
def a ultva lue) $
MA I LPATH filena mes tocheckf ornew ma i
l;uses
follow i ngf orms.
$
FIG N ORE colon- sepa ratedli st ofs uf fi
x es g iving :se par a tor;f il
e na mema ybef ollow ed
na me=w o rd setna metow o rd the set off ilena me s to i gnor ew hen by ?me ssa g e ; $ _ i n me ssag e i s
na me [inde x]=w o rd doi ng f ilena me comple ti
on usi ng ma tch e d ma il f ile na me.Over r i
des
FUNCTI
ONS
Functions run in thesa meproce ss a s theca lli
ngscr ipt,
setelementi nde xofa rr
a yna metow o rd rea dline $ MA I L
and sh arethe open f il
es a nd cur rent directory.They
na me=( word. ..
) G LOBIG N ORE colon-
$ sepa ratedlistofpa tterns g iving $
OLD PW D previ ous w ork ingdir ectory
access theirpa rame ters li
k eascr ipt, via$ 1, $2 and so
setindexedar ra yna metow ords the set off ilena me s to i gnor ew hen $
OPTA RG va lueofla st a rgument proce sse d by
on. $0does not change. return ma ybeused i nsidea
na me=( [
num] =w o rd. ..
) doi ngpa tternma tchi ng g etopts
function or .scr ipt.Functions sh are traps w ith the
setgi ven i ndices ofa rrayna metow ords $
G ROUPS[ *] readonlya rra yva riablew ith theli st $
OPTERR if set to 1 ,di s pla y error messa ges
parent script,ex cept f orDEBUG .Functi ons ma y be
ofgroups theuserbe long s to from g etopts ( de fa ult:1 )
recursive,andma yh aveloca lvariables, declaredus ing
$
histchars char a cte r s tha t control csh- sty le $
OPTIND inde xofl ast a rgument proce sse d by
declare,loca l,ortypese t.Functi ons ma ybeexported
hi story ( def ault: ! ˆ# ). See H i stor y g etopts
intotheenvir onmentw ith .
Subst itut ion

9 1
0 1
1 1
2
I
NPUT/
OUTPUT CONTROL COMMA N DS CON DI
TIONA L EXPRESSI
ONS BUI
LT-
I
N COMMA N DS
Redir
ections are donelef t toright,afterpipes a
reset !pipe l
ine Us edw iththe[
[..
.
]]compoundcommand, w hi
chdoes These commands are execu
ted dir
ectly bythe shell.
up.Def aultfil
edescr iptors arestdin andstdout.Fil
e executepi pe li
ne .I fex it sta tus w a s non- zero,e xit notdopattern expansion orw ordspli
tti
ng. A lmosta
llacce
pt toma rkthee ndofoptions.
descr
iptors above2 arema rkedclose-on-exec. zero. Ife x itsta tus w a s zero,e x it1
stri
ng tr
uei fstringis notNULL . fi
le
casew o rdin [ [(]pa t1 [| pa t2] ...)li
st; ;] ..
. esa c
&>w o rd sendstdoutandstderrtow o rd file tr
uei ffi
leex ists ( is preferred) source f ile
executel ista ssoci a tedw ithp a ttha tma tches w o rd.
>&w o rd sendstdoutandstderrtow o rd f i
le tr
uei ffi
leis ablockdevi ce read and execute commands f rom f il
e .I f
Fi eld s pli ttingi s not donef orw o rd.p at is abash
[n]<f i
le usef i
lef ori nput file tr
uei ffi
leis achar a cte rdevi ce arg uments,sa ve and re store positiona l pa rams.
pattern ( se ePa tter ns) .|i s us edto indica tean OR
[n]>f i
le usef i
lef oroutput f i
le tr
uei ffi
leis adir ectory Se arch$ PATH ;i fnoth ingf ound, looki n thecur r ent
condition. Us eleadi ng(i fc asei si ns ide$ ()
[n]>| fi
le li
k e>, butoverri des noclobber file tr
uei ffi
leex ists dir e ctory
forna me[ in w ords];dol ist;done
[n]>>f ile li
k e>but a ppendtof i
l eifite xists f
i l
e tr
uei ffi
leis areg ularf ile : nullcommand;returns 0e x itsta tus
sequentia llya ssi gn ea chw o rdtona mea ndexecute
[n]<>f ile open f i
leforre ad/ w rite( def ault:f d0) f i
le tr
uei ffi
leha s se tgidbitse t [ se ete st
list.I f in w ords i s mi ssing use the positi ona l
[n]<&m dupli ca teinputf iledescr iptorfrom m fil
e tr
uei ffi
legroupis ef fectivegi d alias [ ][ na me [=va lue ]...
]
par a me ters
[n]>&m dupli ca teoutpu tfiled escriptorfrom m f i
le tr
uei ffi
leis asy mboli clink crea te a n ali as.W ith no a r
guments,pr int a ll
[func tion]f unc( ){l ist;}
[n] closei nputf iledescr iptor f i
le tr
uei ffi
leha s stick ybitse t a li
a ses. W ithna me ,pr inta lias va luef orna me
def inef uncti on f unc, bodyi sl ist( seeFunct ions)
[n] closeoutputf iledescr iptor f i
le tr
uei ffi
leis asy mboli clink pr inta lias bef oree acha li
a s
ifli
st1 ;then l ist2[ ;elifl st3;then l
i ist4] ..
.[;elsel st5];f
i i
[n]<<w o rd stri
ng tr
uei fstringha s non- zeroleng th bg[j obi d]
if executing l i
st1r etur ns successf ul ex it sta tus,
input comes f rom thesh ellscr ipt;trea t ali new ith fil
e tr
uei ffi
leex ists a ndw a s modi fiedsince
putj obi din theba ck ground
executel ist2 else. ..
wo rda s EOF on i nput. I fanyofw o rdis quoted, no la
stre ad bind[ ma p][ ]
selectna me[ in w ords];dol ist;done
additiona lproce ssi ngi s doneon i nputbythesh ell. option tr
uei foptionis on bind[ ma p][ f unc][ k ey seq][ f unc]
pr int amenuofw ords, promptw ith$ PS3 andreada
Other wi se: f
ile tr
uei ffi
leow neris ef fectiveui d bind[ ma p] f il
e
linef rom stdin,sa vi ngitin $ REP LY.I ftheli nei s
• dova r
iable, command, arithmeticsubstitutions fil
e tr
uei ffi
leis af i
fo( na medpi pe) bind[ ma p]k e yse q: func
the number of one of th ew ords,se t na meto it,
• ignoreescapednew li nes f
ile tr
uei ffi
leis rea dable di s pla y and/ or modi f y rea dline f unction a nd k ey
oth e rw i se set na meto NULL.Executel st.I
i fin
• use\toquote\ , $,`, a ndf irstcha racterofw o rd fi
le tr
uei ffi
leha s non- zerosize bi ndi ngs. Th esy nta xi s samea s for˜ /.inputrc
w ords is mi ssing use the positiona l para me ters.
[n] w o rd a sa bove, butw ithl ea di ngtabs i gnor ed fil
e tr
uei ffi
leis asock et fil
e readnew bindi ngs f rom f il
e
bashautoma tica llyr epr ints themenuattheendof
f
iledes tr
uei ffi
ledes i s ate rmi nal listthena mes ofa llrea dlinef unctions
Of&>and>&, thef irst i
s preferred. I t is e qu iva lent to theloop
fil
e tr
uei ffi
leha s se tuidbitse t ma p us ethek ey ma pma p
>w o rd2>&1 . time[ ]pi pe l
ine
fi
le tr
uei ffi
leis w rita ble listrea dlinef uncti ons a ndbi ndi ngs
execute pi pe line ;pr int e lapsed,sy stem and use r
fil
e tr
uei ffi
leis e xe cuta ble forre- rea di ng
times on stderr.
EX ECUTI ON ORDER string tr
uei fstringha s zeroleng th listrea dlinef uncti ons a ndbi ndi ngs
pr intti mes i n POSI Xf orma t
A ll s ubstitutions a nd I /O r edir ections a re performed fi
le1 f il
e 2 tr uei ffi
le 1is new e rth a nf il
e 2orf ile2 func sh ow w hichk ey s invok ef unc
The$ TI MEFORMA T va ria blecontrols thef orma tof
bef oreacommandi sa ctua llyexecuted. does notex ist k e yseq re movebindi ngs f ork e y se q
theoutputif is not us ed. ba shuses thevalue
fi
le1 f i l
e2 tr uei ffi
le 1is olderthan f il
e 2orf il
e2 listrea dlinek eysequences a ndma cros
ba sh ma inta ins a n inte rna l has h ta ble f or cach ing $ ’\nrea l\t%3lR\ nuser\t%3lU\ nsys\t%3lS’i ftherei s
does notex ist forre- rea di ng
ex terna l commands.I nitia lly,this table i s empty . As novaluef or$ TI MEFORMA T
fi
le1 f i l
e2 tr uei ffi
le 1andf ile2a reth esa mef i
le listrea dlinek eysequences a ndma cros
commands a refoundbyse a rchi ngthedir ectori es listed untill ist1 ;dol st2;done
i
string==pa tte
rn func re movek eybi ndi ngs f orf unc
in$ PATH , theya readdedtothehas hta ble. lik ew hilebutnegatethete rmina tionte st
tr
uei fstringma tches pa ttern listrea dlineva riablena mes a ndva lues
w hilel i st1 ;dol ist2;done
Thecommandse archorderis shellf uncti ons first, bui lt- string! =pa ttern forre- rea di ng
execute l i
st1 .I f la st command i n l ist1had a
in commands second,a ndexte rna lcommands ( first in tr
uei fstringdoes notma tchpa ttern listrea dlineva riablena mes a ndva lues
successf ul ex it sta tus,e x ecute l st2 f
i ollow ed by
theinte rna lhas htable, andthen vi a$ PATH )thir d. string 1 <stri ng2 brea k[ n]
list1 .Repeatuntilla st commandi nl ist1r eturns a n
tr
uei fstring1 is bef orestri ng 2 ex itf rom enclosingfor,w hile,untilorse lectloop.
unsuccessf ulex itsta tus
string 1 >stri ng2 Ifni s suppli ed, ex itfrom n’ thenclosi ngloop
SI G N A LS A ND TRAPS ((.
..
))
tr
uei fstring1 isa f
terstri ng 2 builtin sh ell
-bui l
tin [a rgs. ..
]
Signa lhandli ngi s donew iththetra pbui lt-in command. a rithme ticeva lua tion, likele t" ..
."
ex p1 e xp2 truei fex p1 equals e xp2 execute sh e l
l-bui ltin w ith given a rgs and r eturn
Thew o rda rgument descr ibi ng code to execute upon [[expr essi on] ]
ex p1 exp2 truei fex p1 does not equa le xp2 sta tus. Usef ulf orthebodyofas hellf uncti on th a t
rece ipt of the si gna li s scanned tw i ce byba sh;once eva lua tee x pr essi on,r etur n success f ulex itsta tus if
ex p1 e xp2 tr uei fex p1 is le ss than e xp2 redef ines abuilt- in, e.g. ,cd
w hen thetra p commandis e x e cuted,a nd a ga in w hen true, unsuccessf ul i f f a lse ( see Condi tiona l
ex p1 e x p2 truei fex p1 is g rea terth a ne xp2 cd[ ][ dir]
thesi gna lis caught.Thereforeit is b e st tousesing le Expr essi ons f orde ta ils)
ex p1 e xp2 tr uei fex p1 is le ss than orequa ltoe xchang
p2 e cur rent dir ectory to di r( $ H OME def a ult).
quote s forthetra p command.Tra ps a re execu tedi n (lst)
i
ex p1 e xp2 truei fex p1 is g rea terth a nor Dodir ectorypaths ea rchusingva lueof$ CDPATH
orderofsi gna lnumber .Youca nnot changethesta tus executel istin as ub- sh ell
equaltoe xp2 us elog icalpa thf orcd. ., $PW D ( def ault)
ofasi gna ltha tw a signoredw hen thesh ellsta rtedup. {l st;}
i
(ex pre ssion) tr uei fex pressi oni s true, forg rouping us eph y sica lpathf orcd. ,
. $ PW D
executel istin thecur r
entshell
Traps on DEBUG happen af tercommands a reexecu ted. !e x pre ssion tr
uei fex pressi oni sf alse Ifbothareg ive n, thel ast oneon thecommandli ne
ex p1 &&e x p2 truei fex p1 AND e xp2a r
etrue w ins
Back grounded commands ( those follow ed by&)w ill ex p1 ||ex p2 tr
uei fex p1 ORe xp2i s true cd [ ]
ignoreth eSIG I
N T andSIG QUI T signa ls i
fthemonitor chang ecur rentdir ectoryto$ OLDPW D
option i
s tur
nedof f.Otherwi se,theyi nhe ritthevalues Iffil
ei s/ dev/ f
d/ n,then, i
fthereis no/ dev/ ddir
f ectory ,
command[ ]na me[ arg. ..
]
ofthepar entba sh. fil
e descr iptor n is check ed.Other wise,the r ea l
w ithout or , executena mew ithar guments a rg
/dev/ fd/nf ileis check ed.Linux ,FreeBSD, BSD/OS ( and
us eadef aultse a rc hpa th ,not$ PATH
ma ybe others) re turn i nfo for the i ndica
ted f il
e
A RRAYS pr int aonew ordde scri ptionofna me
descr iptor,inste adofthea ctual/dev/ ddevicef
f il
e.
Ar r
a ys i
n bash h ave no li mits on the number of pr int averbosedescri ptionofna me
elements.A r rayi ndices start at0 .A rr
a ysubscripts Both && and | |a re short cir cuit.Opera nds of continue[ n]
can be a rithmeti
c expressi ons.A rray elements need compar ison oper ators underg oa rithmetic evalua tion. do next itera tion ofenclosi ngfor,w hile,untilor
not be contiguous.ba sh does not h ave a ssocia
tive For==and! =, quotea nypartofpa tte
rn totreat ita s a selectloop.I fn i s suppli ed,ite ra ten’ thenclosing
arrays. string. loop

1
3 1
4 1
5 1
6
BUI LT- I N COMMA N DS ( cont inued) BUI LT- I N COMMA N DS ( cont i
nued) BUI LT- I N COMMA N DS ( cont inued) BUI LT- I N COMMA N DS ( cont inued)
decla re[a fFirx][ ][ na me [=va lue ]] export[ ][ na me [=va l
ue ]. ..] k ill[si g ]jobi d. .. rea donly[ ][ na me =va lue. ..]
typese t[a fFirx][ ][ na me [=va lue ]] w ith no a rguments,pr int na mes a nd va lues of k ill[ si g na me ][ si g num]j obi d. .
. ma rkna me s read- only ;pr intli sti fnona me s
set a ttributes a nd va lues of va ria bles.I nside exporte dva riables. Other w ise, exportna me s tothe send SI G TERM or g i
ven si gna l to na med j obi ds. ea chna memustbea n ar ra y
functi ons,cre a tene w copi es oftheva riables. Using envir onmentofcommands Signa ls a re na me s li sted i n / usr/ inc lude / signa l.h ea chna memustbeaf uncti on
+inste adof tur ns a ttri bute s of f.W ithno na mes na me s refertofunctions w ithorw ithoutthepr efix‘ ‘ SIG’’
.Stoppedj obs get pr intrea donlybef oree achva riable
or a ttri bute s, pr int eve ry va riable’ s na me a nd stopexporti ngea chna me a SIG CON T f irst i f si gi s either SI G TERM or re turn [ n]
attribute s pr intexportbef oree achva riable SIG H UP ex itf unctionor. scr iptw ithr etur nvaluen. W ithno
na meis a n ar ra y fc[ e ditor][ ] [frst[
i last] ] [ si g s...] n, retur n s ta tus ofla stcommand. Ifnotin f uncti on
ea chna mei s af uncti on pr int arang eofcommands f rom f irsttol astfr om la st li
st si gna l names a nd/ or numbers.I f si g is a or. scr ipt, pr inta nerrormessa ge
don’ tsh ow f uncti on def initions ( bodi es) $ H ISTSIZEcommands nume rica lex itsta tus,pri ntthesi gna ltha tk ill
edthe set[options][ option][ w ords]
na meis a ni nte g e r;a rithme tic run e ditori fs uppli ed;i fnot, us efirstof proce ss setf lag sa ndoptions ( seeOpt ons Toset)
i . w ords set
eva lua tioni s doneupon assi gnment $FCEDI T, $ EDITOR, orvion let a rg. .. positiona lpa ra meters
ma r kna me s rea donly commands;e x ecuteresult( s) eva luateea cha rga sa n arithme ti
cexpressi on;e xit0 set[ + options][ + ooption][ w ords]
ma r kna me sf orexport li
ston s ta ndardoutputi nste adofediting ifthe la st e x pre ssi on w a s non- zero,1oth erw i se unsetf lag sa ndoptions
dirs [ ][+ n][n] don’ tpr intlinenumbers (seeAr i
thmet icEva lua tion) sh ift[ n]
dis playthedir ectorystack reverseorderofcommands loca l[ na me [=va lue ]...] rena mepositiona lpara me te rs;$ n+1 =$ 1. ..
+n s how n’ thentryf rom lef t,n 0 [old=new ][ comma nd] crea tev a ria bles w ith the given values loca l to a ndef aults to1
n s how n’ thentr yf rom r ight, n 0 s ubstitutenew f orol di n comma nd( orla stcommand function.W ith no operands ,pr int ali st ofloca l s hopt[ ][ option. ..]
clea rthedir ectorystack ifnocomma nd)andexecutetheresult va ria bles. Mustbeusedi ns ideaf unction pr int or ch a nge values of shell options.W ith no
pr intalong erf orma tli sti ng fg[j obid] logout a rguments, pr intshelloption i nf orma tion
pr intthestackoneentryperline putj obidin thef ore g round ex italog in s hell onlychang e options
pr intthestackoneentr yperline, w ith g etopts optstr ingna me[ arg. .
.] popd[ ][ +n][n] pr intse ttings forre -readi ng
indexnumber s parsepa rame ters a ndoptions ( seeba sh (
1 )
) remove entri es f r
om the dir ectorystack .W ith no qui etmode;e x itsta tus indi cate s
disow n [ ][ ][ job. ..] hash[ ][ f i
le ][ na me ] arg uments, removethetope ntryandcdther e optionsta tus
w ithno options,removenamedj obs f rom theta ble w ithno a rguments,pr int thehas hta bleconte nts, +n re moven’ thentryf r
om lef t, n 0 se t( enable )gi venoption;w ithno
ofa ctivej obs gi vinghitcount a ndf ilena me n re moven’ thentryf r
om r ight, n 0 options, pr intthosetha ta rese t
re moveorma rk ( w ith )allj obs file ente rfi ef
l orna mei n thehas hta ble don’tchangedir ectory unse t( disa ble)gi venoption;w ithno
ma r kea chj obtonotrece iveaSIG H UP clea rthei nte rna lhas hta ble printff orma t[ar g. .
.] options, pr intthosetha ta reunset
w henba shte rmi nate s A ssi gnmentto$ PATH a lsoclea rs thehas hta ble printoutput li keA N SIC printf ,w ithex te nsi ons (SeeOpt ions Tos hopt)
us ew ith toma rk justrunni ngj obs help[ pa tter
n] %b ex pandesca pesequences i n s trings s us pend[ ]
echo[ ][w ords] pr int help.W ithpa tte rn,pr int help about a ll the %q pr intquote dstri ngtha tca nbere - r
e ad s us pendthesh elluntilSIG CON T is recei ved
echow ords; is notspecia l commands tha tma tchpa ttern For ma tconversi ons a rereuseda s needed forcesuspensi on, eve nf orlog in s hell
ex pand\ - esca pes ( seee ch o(1 )) history[ n] pus hd[ ][ di r] te st
neve rexpand\ -esca pes [file] pus hd[ ][ + n][n] eva luate conditi ona l expressi ons ( see Opt ions To
don’toutputtra ilingnew li ne history[ ] add an entr y to the dir ectory stack .W ith no te standCondi t
iona lExpr e ssions)
printfi s moreporta ble arg[ .
..] arguments, ex changethetoptw oentr ies times
ena ble[ ][ f i
le][ na me. ..] arg[ ...] +n rota teth esta c k soth atth en’ th pr inta c cumula tedpr oce ss times
enable a nd disa ble shell bui lt- ins,or load and w ith no options,pr int the command hi story .A n entryf rom lef ti sa tthetop, n 0 tra p[ ][ wo rd][ sig s]
unloa d new bui lt- i
ns f rom sh a red li br a ry f i
les. a rg ument ofn pr ints onlyn li nes.I fs uppli ed,use n rota teth esta c k soth atth en’ th execute w o rdi f si gna l in si gs rece ived.si g s a re
Di sablingabui lt-i
na llow s useofadi skf i
lew iththe fiei
l nste a dof$ H ISTFI LE entryf rom r ightis a tthetop, n 0 numbers or signa l na mes w ith or w ithout ‘ ‘SI
G’ ’
.
sa mena mea s abui lt- i
n append new hi stor yli nes tohistoryf ile don’tchangedir ectory W ith no w o r d orsi g s,pr int tr aps.W ith no w o rd,
pr inta llbuilt- i
ns , w iththeirsta tus clea rthehi storylist dir pushdi ronthestacka ndcdther e rese tsi g s toe ntrydef aults. Ifw o rd sigs
deleteabui lt-in loa dedw ith readnew hi storyli nes in thef il
ei ntoth e pw d[ ] to e ntrydef aults.I fw o rdis thenullstring, ignore
f
il
e loa danew bui lt- in na mef rom f i
le inte rna lhi storyli st printw ork ingdir e ctoryna me sig s. Ifsi gsi s 0orEXI T, executew o r don exitf rom
disa blena me ,orpr intdi sa bledbui lt-i
ns per form hi storys ubstitution andpr int pr intlog ica lpa th( default) sh ell.I f si g s i s DEBUG ,r un w o rd a fter every
w ithnona me s ther esults pr intphy sica lpa th command.
pr int ena bledbui lt-ins replaceinte rna lhi storyw ithconte nts of Ifbothareg iven, thela st oneon thecommandli ne pr intali stofsigna lnames a nd numbers
pr intonlyPOSIX speci a lbuilt- ins historyf ile wi ns pr inttraps w ithquoti ng
eval[ w ords] placethea rg si ntothehi storylist na me ][ ][ prompt][ name s. ..] type[ ]na me. ..
eva lua tew ords a ndexecuteresult forla teruse rea dstdin and assi gn tona me s.$ IFS s pli ts input. descr ibehow thesh elli nte rpr ets na me
exec[ na me ][ ][ w ords] w riteth ei nte rna lhi storytothef ile $REP LY is se ti fnona megi ven. Exi t0unless end- pr inta llpossiblei nte rpr eta tions
executew ords in pla ceofthesh ell.I fr edir ections jobs [ ][ j
obi d. ..] of- f
i leencounte red ofna me
only ,changethesh ell’s open f i
les comma nd[ arg s. ..
] readw ords i ntoi ndexedar ra yna me pr intthenameofthef il
etoexecutei f
usena mef ora rg v[ 0] listinf orma tion aboutj obs userea dlinei freadi ngf r om ate rmi nal na meis a n ex te rna lprog ra m
clea rtheenvir onmentf irst alsoli stproce ss i d pr intprompti freadi ngf r
om ate rminal pr int ak ey w ordde scri bingna me
placea on a rg v[ 0 ]( lik el og i
n(1 )) onlyli ststoppedorex itedj obs bef orer e adi ng
Iftheexecfa ils,non- inte ra ctivesh ells e x it,unle ss onlyli stproce ss groups a t endofli nedoes notdoli ne
thes hoptoption execf a ili s set onlyli strunningj obs continua tion
exit[ n] onlyli ststoppedj obs
ex itw ithr etur nvaluen. Use$ ?i fnon replacea nyj obi di n thecommandli ne
w iththecor respondingproce ss groupID,
andexecuteth ecommand

1
7 1
8 1
9 20
BUI LT- I N COMMA N DS ( cont i
nued) OPTI
ONS TO set OPTI
ONS TO set(
cont
inued) OPTI ONS TO s hopt( cont
inued)
ulimit[ type][ options][ li
mi t] Thesetcommand i s compli
cated.H ereis asumma ry. printcommands a s they’reexecuted, lithist
setorpr intper -proce ss limits Use + inste
a d of to tur n options of
f.W ith no precededbyex pandedvalueof$ PS4. if cmdhist is a lso enabled, sa ve multi- l
ine
type( defaultis both) : arguments,set pr
ints the names a nd values of a
ll Outputis quotedforla terreuse commands w ithnew li nes, notse mi-colons
har dlimi t var
iables. turn off , , s toplook i
ngf orflags; ma ilw a rn
softlimi t anyre ma ininga rgs setth e pr int aw a rni ngmessa gei faf ilebeingcheck edf or
set[abBCefh
Hk mnpPtuvx ][ooption. ..][a rg. ..
]
options: positiona lpa rameters ma il w a s accessed s i nce the la st ti me it w a s
automa tica llyex portvar iables upon
all(dis pla yonly ) donotchangef lag s;setpos iti
onal check ed
assignment
coref ilesize pa rame ters from a rgumentlist; nocaseglob
pr intj obcompletion messa ges

‘k’’ofda tasegment w ithnoa rg s,unsetthepositi onal do a case- insensitive ma tch w hen expandi ng
immedi ate ly ,don’ tw a itf orne xtprompt
ma ximum f i
lesize pa rame ters pathna mes
ena blebr aceexpansi on( def ault)

‘k’’ofphy sica lmemory nullg lob
force>|toover w ritef ore x istingf iles
ma ximum f i
ledescr iptor+1 OPTI
ONS TO s hopt re movepa tterns tha t don’tma tcha nyf ile,ins tea d
ex ituponnon- zeroexitf rom acommand
sizeofpi pebuf fers Thes hoptcommandsets orunsets anumberofoptions ofle a vingthem unchangedin thecommandli ne
disa blepa ttern expans i on

‘k’’ofsta ckseg ment thata f
fect how bashbeh aves.Thi
s section descr
ibes promptva rs
sa vecommandloca tions i n the
cpus econds eachoption’ s ef
fectw hen enabled.Unless noted,they do pa ra meter expansi on on the prompt va ri
ables
interna lha s hta ble(de fault)
ma xproce sse sf oroneuser arealldisabledbydef a ult. bef oreprintingthem. Enabledbydef ault
ena ble! -sty lehistor y( def a ult)

‘k’’ofvirtualmemor y sh ift_ verbose
placea llva riablea ssignments i n cdable_ vars
is a ssumedi fno options a r
egi ven. Thesizef or pr int a n error messa ge w hen the s h ift count is
theenvir onment( obsolete) trea ta na rgumenttocdtha tis notadir ectorya s a
is in 51 2- by teblock s;theothers a rei n s izes of grea terth an thenumberofpositiona lpara meters
run back groundj obs i n theirow n va riablew hoseva luei s thedir ectoryna me
1 024by te s sourcepa th
proce ss gr oup, printamessa ge cds pell
uma sk[ ][ ma sk ] use $ PATH to find sh ellf i
les given to the.and
w hen theyex it;se ta utoma tica llyf or atte mpt to cor rect mi nor spelli ng errors i n
setf i
lecr e a tion per missi ons ma sktocomplementof sourcecommands. Ena bledbydef ault
inte ra ctivesh ells on j obcontrolsy stems a rg uments to cd.Er rors tri ed a re tra nspose d
ma ski focta l, orsy mboli cva luea s in ch mod.W ith
readcommands w ithoutexecutingthem char a cters, a missi ng character or a n e xtra
no a r
guments, printcur rentma sk . A n octa lma ski s
per missi ons to re move, a sy mboli c ma sk i s
(ignoredi finte ra ctive) char a cter. Onlyobey edin i nte ra ctivesh ells SPECI
AL CH A RA CTERS
se topti ons;w ithnoa rguments, pr int check h ash # sta rtofcomment;te rmi na tedbynew line
per mi ssions tok eep
cur rentse tti ngs checktha tacommandin thehas hta blestillex i sts | (pipe)connects tw ocommands
pr intoutpu tforre -readi ng
allexport sa mea s bef oretry i
ng to e xecuteit.I fit does n’t,se a rch ; commandsepa rator
pr intcur r
entma ski ns y mbolicf orm
braceexpa nd sa mea s $PATH & run proce ss in back ground;de fa ultstdin
una lias [ ][ na me s]
emacs usea ne ma c s- sty leli ne check w ins ize from / dev/ nulli fnoj obcontr ol
removea liases na mes
editor( default) checkthe w i ndow size a f ter each command and && onlyr un f ollow ingcommandi fprevi ous
re movea lla liases
erre xit sa mea s upda te$ LINES and$ COLUMN S commandcompletedsuccessf ully
unset[ ][ na me s]
ha sh a ll sa mea s cmdhist |
| onlyr un f ollow ingcommandi fprevi ous
unsetva ria bles na me s( sa mea s )
histexpand sa mea s atte mpttosa vea llli
nes ofamulti- li
necommandi n commandf ailed
unsetf uncti ons na me s
history ena blehi story thehistoryf il
ea s oneline, f ore a syre -editi ng ´ enclosestr ingtobeta ken litera lly
unsetva ria bles na me s
ignoreeof li keI G N OREEOF=1 0 dotg lob " enclosestr ingtoh aveva riable, command
Unsetti ng LI N EN O, MA I LCHECK, OPTARG ,
key w ord sa mea s include f i
les w hose names begi n w ith.i n pa th andarithme ticsubstitutiononly
OPTIND,RA NDOM,SECON DS,TMOUT and _
monitor sa mea s ex pansi ons $() in-linecommands ubstitution( new sty le)
removes their speci al meani ng, eve n i f us ed
noclobber sa mea s execfa il ` in-linecommands ubstitution( oldstyle)
a f
te rw ards
noexec sa mea s k eep non- inte r
a ctivesh ells f rom ex iti
ngw hen exec (.
(.
.)
) arithme ticeva luation, li
k ele t" ..."
wa it[jobi d...]
noglob sa mea s fa ils $(.
(.
.)
) in-linea rithme ticeva lua tion
wa itforj obj obi d;ifnoj ob, wa itf ora llch ildren
notif y sa mea s expand_ alia se s \ trea tfollow ingcha racterlitera lly
nounse t sa mea s ex pand a li
a ses a s descr ibed i n Al iases.Ena bled \new line li
necontinua tion
OPTI ONS TO te st onecmd sa mea s automa tica llyi n inte ra ctivesh ells
Thete stcommand, andits sy nony m[ ..
.],arebui lt-
in to physica l sa mea s extglob
posix obeythePOSIX 1 00 3.2
JOB I
DS A N D JOB CONTROL
ba sh. Thecommandaccepts a lloftheoptions li stedi n enableth ee x tendedpattern ma tchingf a cili
ties (see Jobs canberepre
senteda
sfollow s:
theCondi tionalExpr essions se ction. H ow ever,sinceitis sta nda rd Pa tter ns)
acommand, options a nda rguments mustbequote dto pr ivileged sa mea s hista ppend j
obi
d thej obidentif
ierforaj ob,w here:
g etpr operbehavi or, andnor ma lpa ttern expans ion and verbose sa mea s appendthecur renthi storyto$ H ISTFI LEupon exit, %% cur r
entjob
fields pli
ttinga redone. Pa renth eses usedf orgroupi ng vi us eavi -sty lelineeditor inste a dofover w ritingi t %+ cur r
entjob
must bequoted.A rithme ti cexpansi on is not donef or xtrace sa mea s histreedit previous j
ob
nume ricoper a tors,a nd pa ttern ma tchingi s not done don’ tr ea d$ EN V, donotta kesh ell ifusi ngrea dlineandahistor ys ubstitution f ails, the %?str jobuni quelyidentif
iedbystr
for==and! =. testcompli e s w ithPOSI X. functi ons f rom envir onment, andignore userca n re -edittheli ne %n jobnumbern
options i n$ SH ELLOPTS envir onment histverify %pref jobw hosecommandli nebegi ns
The and options h a ve the f ollow ingmea ni
ngs, va ria ble w ithpref
if usi ng rea dline,loa d the results of history
instea doftheones li stedi n Condi t
iona lExpre ssi
ons: follow thephy sica ldirectorystructur e s ubstitutioni ntorea dlinef orf urtherediting Us ually,aproce ss I
D maybe used i
ns te
a dofaj d.
obi
logicalA N D forcommands thatchangethedir ectory hostcomple te Commands tha t takeaj dus ethecur
obi rentj
ob i
fno
logicalOR readandexecuteonecommand, ifusi ngrea dline, attempthost comple tion on w or d j
obi dis suppli
ed.
then exi t conta i
ni ng@
ma k eita n er rortosubstitutea n unset huponexit Tra
ps on SIG CH LD executew heneveraj
ob comple
tes.
va ria ble sendSIG H UPtoa lljobs w hen ba shex its Thecommands f gandbga reonlya vai
lableon s ystems
pr intinputlines a s they ’rer e ad inte ra c tive_ comments that support j
ob control.Thi s i
nclude s Linux ,BSD
ini nte rac tivesh ells,aw ordsta rti ngw ith#sta rts a systems,System V Relea
se4, andmostUNI X systems.
comment. Enabledbydef ault
21 22 23 24
REA DLI
NE REA DLI
NEVA RI
A BLES
Therea dlinelibra ryimplements commandli neediting. Variables control di
fferent a spects of readline’
s
By def a ult,it provi des a n ema cs editing i nterface, behavior. Yousetavariablew ith
although a vi i nterface is a vai
lable.rea dline is
setva
ria
bleva
lue
initi
a li
zedeitherf rom thef i
lena med by$ INPUTRC ( i
f
set),or from ˜ /inputrc.I
. n thatf ile,y ou ca n use Unless otherwi
senoted, va ues h
l ould beeitherOn or
conditi ona ls, define k ey bi ndings for ma cros a nd Off.Thedescr iptions below descr ibetheeffect w hen
functi ons,a ndsetva riables. the va r
iable i
s On.Def ault values are sh ow n in
parentheses.
From thebashleve l, thebindcomma ndallow s y ou to
add,r emove a nd change ma cro a nd k ey bi ndings. bell- style( audible)
Th erea refi vei nputmodemap names tha t contr olthe def ines how rea dlines h ouldr ingthebell:
action ta k enf or e achinput char acte r. Thema p na mes audible ringthebell
a reemacs,emacs- standard,emacs- me ta,emacs- ctlx, none neve rringthebell
vi,vi - command,andvi- insert.emacs i s thesa mea s visible fla shthescr een
emacs- standard, a ndviis thesa mea s vi- command. comment- begin ( # )
Youchoos ew hi cheditory ou pr eferw ith ins ert this stri ng f or readline- inse rt- comment,
or in y our˜ / .bash rcf il
e, ora trunti me. (boundtoM- #i ne ma c s modeandto#i n vimode)
comple tion- ignore -ca se( Of )
f
rea dlineundersta nds th ec h a racter na mes DEL,ESC, ignoreca sew hen doingcomple ti
ons
LFD, NEW LI NE, RET, RETURN, RUBOUT, SP A CE, SP C and comple tion- que ry- items ( 1 00)
TA B. ifthenumberofcomple tion items i s less than thi s
va lue, placethem i n thecommandli ne. Other wi se,
REA DLI NEDI RECTI VES asktheuseri ftheys h ouldbeshow n
Dir ectives i n the. inputrc f ile provi de conditiona l and conve rt- me ta( On)
includef acilitie s simila rtotheC preproce ssor . trea tcha ra cters w iththeeighthbitseta s theme ta
versi on oftheequiva lentseve n bitchar a cte r
$ include disa b le -comple tion ( Of )
f
includeaf il
e, e.g. , asy stem- wi de/ etc/ inputrcf i
le donotdocompletion
$ if editing- mode( emacs)
sta rt a conditi ona l,f or te rmina l or appli ca tion set the initia l editing mode.Possi ble va lues a re
speci ficsetti ngs. Youca n te stthef ollow i ng: emacs orvi
applica tion= te sttheappli ca tion, e.g. bashorgdb ena ble- k eypad( Of f)
mode= te sttheeditingmode, e ma c s orvi atte mpttoenableth ea pplication k ey pad. This ma y
te rm= te stthete rmi na lty pe beneededtoma k ethea rrow k ey s w ork
Theuseofapplica tion=is optiona l;e. g. ,$ ifBa sh expand- tilde( Of f)
$else atte mptti ldeexpansi on a s pa rtofw ordcompletion
sta rtthe‘ ‘
else’ ’pa rtofaconditi ona l input- meta( Of f)
$endif me ta - fla g( Of f)
fini s haconditiona l ena bleei ghtbitinput. Thetw ova r
iablena mes a re
sy nony ms
keyma p( emacs)
REA DLI NEKEY BI N DI NGS set thecur rent k e yma p. SeeReadl i
nef or ali st of
Key s bound to ama cro placethema cro te x ti nto the a llow ed va lues.The editing- mode va r iable a lso
input;k eys boundtoaf unction r un thef unction. a ffects thek ey ma p
Youca n usetheseesca pesequences i n bindings: ma rk -dir ectories ( On)
appenda/ tocompleteddir ectoryna mes
\a a lert( bell) \r ca rr i
ager eturn ma rk -modi f ied- lines ( Of f )
\b ba ck spa ce \t horiz onta ltab( TA B) placea*a tthef rontofmodi fiedhi storyli nes
contr olpr efix \ v verticalta b output- meta( Of f)
\d dele te( DEL) \ \ ba ck sla sh pr int cha ra cters w iththeei ghthbitsetdir ectly,not
\e esca pe( ESC) \ " liter al" a s M- x
\f for mf eed \´ liter al´ print- comple tions - horizonta lly( Of f)
me tapre fi x \ddd octa lva lueddd di s pla ycomple tions h orizonta lly,w iththema tch es
\n new li ne \xhh h hexva lueh h h sor te da lphabe tica lly, inste adofverti callydow n the
Ma cr os a ndf uncti on bi ndi ngs lookli ke: screen
show - a ll- i
f- a mbiguous ( Of f)
ma cro: ke y-seq:" tex t" immedia tely li st w ords w ith multiple possi ble
functi on: ke y-seq:func tion- na me comple ti ons, ins te a dofringi ngthebell
Ma cros h a ve quoted te xt on th e right of the colon; visible- sta ts ( Of f)
functi ons h ave f unction na mes.A k ey-se qi s eithera w hen li sti ng possi ble comple tions, append a
si nglecha racterorch a racterna me( sucha s )
, char a c te rtha tdenote s thef i
le’s ty pe
or a quote
d stri
ng of c
har
a c
ters (
single or double
quote
s). Mor einf
ormati
on aboutreadlineca
n bef
oundon-
li
neat
http:/
/www.ssc.com/ bash.
ssc/
25 26

You might also like