bashref.texi 321 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973
  1. \input texinfo.tex @c -*- texinfo -*-
  2. @c %**start of header
  3. @setfilename bashref.info
  4. @settitle Bash Reference Manual
  5. @include version.texi
  6. @c %**end of header
  7. @copying
  8. This text is a brief description of the features that are present in
  9. the Bash shell (version @value{VERSION}, @value{UPDATED}).
  10. This is Edition @value{EDITION}, last updated @value{UPDATED},
  11. of @cite{The GNU Bash Reference Manual},
  12. for @code{Bash}, Version @value{VERSION}.
  13. Copyright @copyright{} 1988--2016 Free Software Foundation, Inc.
  14. @quotation
  15. Permission is granted to copy, distribute and/or modify this document
  16. under the terms of the GNU Free Documentation License, Version 1.3 or
  17. any later version published by the Free Software Foundation; with no
  18. Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  19. A copy of the license is included in the section entitled
  20. ``GNU Free Documentation License''.
  21. @end quotation
  22. @end copying
  23. @defcodeindex bt
  24. @defcodeindex rw
  25. @set BashFeatures
  26. @dircategory Basics
  27. @direntry
  28. * Bash: (bash). The GNU Bourne-Again SHell.
  29. @end direntry
  30. @finalout
  31. @titlepage
  32. @title Bash Reference Manual
  33. @subtitle Reference Documentation for Bash
  34. @subtitle Edition @value{EDITION}, for @code{Bash} Version @value{VERSION}.
  35. @subtitle @value{UPDATED-MONTH}
  36. @author Chet Ramey, Case Western Reserve University
  37. @author Brian Fox, Free Software Foundation
  38. @page
  39. @vskip 0pt plus 1filll
  40. @insertcopying
  41. @end titlepage
  42. @contents
  43. @ifnottex
  44. @node Top, Introduction, (dir), (dir)
  45. @top Bash Features
  46. This text is a brief description of the features that are present in
  47. the Bash shell (version @value{VERSION}, @value{UPDATED}).
  48. The Bash home page is @url{http://www.gnu.org/software/bash/}.
  49. This is Edition @value{EDITION}, last updated @value{UPDATED},
  50. of @cite{The GNU Bash Reference Manual},
  51. for @code{Bash}, Version @value{VERSION}.
  52. Bash contains features that appear in other popular shells, and some
  53. features that only appear in Bash. Some of the shells that Bash has
  54. borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell
  55. (@file{ksh}), and the C-shell (@file{csh} and its successor,
  56. @file{tcsh}). The following menu breaks the features up into
  57. categories, noting which features were inspired by other shells and
  58. which are specific to Bash.
  59. This manual is meant as a brief introduction to features found in
  60. Bash. The Bash manual page should be used as the definitive
  61. reference on shell behavior.
  62. @menu
  63. * Introduction:: An introduction to the shell.
  64. * Definitions:: Some definitions used in the rest of this
  65. manual.
  66. * Basic Shell Features:: The shell "building blocks".
  67. * Shell Builtin Commands:: Commands that are a part of the shell.
  68. * Shell Variables:: Variables used or set by Bash.
  69. * Bash Features:: Features found only in Bash.
  70. * Job Control:: What job control is and how Bash allows you
  71. to use it.
  72. * Command Line Editing:: Chapter describing the command line
  73. editing features.
  74. * Using History Interactively:: Command History Expansion
  75. * Installing Bash:: How to build and install Bash on your system.
  76. * Reporting Bugs:: How to report bugs in Bash.
  77. * Major Differences From The Bourne Shell:: A terse list of the differences
  78. between Bash and historical
  79. versions of /bin/sh.
  80. * GNU Free Documentation License:: Copying and sharing this documentation.
  81. * Indexes:: Various indexes for this manual.
  82. @end menu
  83. @end ifnottex
  84. @node Introduction
  85. @chapter Introduction
  86. @menu
  87. * What is Bash?:: A short description of Bash.
  88. * What is a shell?:: A brief introduction to shells.
  89. @end menu
  90. @node What is Bash?
  91. @section What is Bash?
  92. Bash is the shell, or command language interpreter,
  93. for the @sc{gnu} operating system.
  94. The name is an acronym for the @samp{Bourne-Again SHell},
  95. a pun on Stephen Bourne, the author of the direct ancestor of
  96. the current Unix shell @code{sh},
  97. which appeared in the Seventh Edition Bell Labs Research version
  98. of Unix.
  99. Bash is largely compatible with @code{sh} and incorporates useful
  100. features from the Korn shell @code{ksh} and the C shell @code{csh}.
  101. It is intended to be a conformant implementation of the @sc{ieee}
  102. @sc{posix} Shell and Tools portion of the @sc{ieee} @sc{posix}
  103. specification (@sc{ieee} Standard 1003.1).
  104. It offers functional improvements over @code{sh} for both interactive and
  105. programming use.
  106. While the @sc{gnu} operating system provides other shells, including
  107. a version of @code{csh}, Bash is the default shell.
  108. Like other @sc{gnu} software, Bash is quite portable. It currently runs
  109. on nearly every version of Unix and a few other operating systems @minus{}
  110. independently-supported ports exist for @sc{ms-dos}, @sc{os/2},
  111. and Windows platforms.
  112. @node What is a shell?
  113. @section What is a shell?
  114. At its base, a shell is simply a macro processor that executes
  115. commands. The term macro processor means functionality where text
  116. and symbols are expanded to create larger expressions.
  117. A Unix shell is both a command interpreter and a programming
  118. language. As a command interpreter, the shell provides the user
  119. interface to the rich set of @sc{gnu} utilities. The programming
  120. language features allow these utilities to be combined.
  121. Files containing commands can be created, and become
  122. commands themselves. These new commands have the same status as
  123. system commands in directories such as @file{/bin}, allowing users
  124. or groups to establish custom environments to automate their common
  125. tasks.
  126. Shells may be used interactively or non-interactively. In
  127. interactive mode, they accept input typed from the keyboard.
  128. When executing non-interactively, shells execute commands read
  129. from a file.
  130. A shell allows execution of @sc{gnu} commands, both synchronously and
  131. asynchronously.
  132. The shell waits for synchronous commands to complete before accepting
  133. more input; asynchronous commands continue to execute in parallel
  134. with the shell while it reads and executes additional commands.
  135. The @dfn{redirection} constructs permit
  136. fine-grained control of the input and output of those commands.
  137. Moreover, the shell allows control over the contents of commands'
  138. environments.
  139. Shells also provide a small set of built-in
  140. commands (@dfn{builtins}) implementing functionality impossible
  141. or inconvenient to obtain via separate utilities.
  142. For example, @code{cd}, @code{break}, @code{continue}, and
  143. @code{exec} cannot be implemented outside of the shell because
  144. they directly manipulate the shell itself.
  145. The @code{history}, @code{getopts}, @code{kill}, or @code{pwd}
  146. builtins, among others, could be implemented in separate utilities,
  147. but they are more convenient to use as builtin commands.
  148. All of the shell builtins are described in
  149. subsequent sections.
  150. While executing commands is essential, most of the power (and
  151. complexity) of shells is due to their embedded programming
  152. languages. Like any high-level language, the shell provides
  153. variables, flow control constructs, quoting, and functions.
  154. Shells offer features geared specifically for
  155. interactive use rather than to augment the programming language.
  156. These interactive features include job control, command line
  157. editing, command history and aliases. Each of these features is
  158. described in this manual.
  159. @node Definitions
  160. @chapter Definitions
  161. These definitions are used throughout the remainder of this manual.
  162. @table @code
  163. @item POSIX
  164. @cindex POSIX
  165. A family of open system standards based on Unix. Bash
  166. is primarily concerned with the Shell and Utilities portion of the
  167. @sc{posix} 1003.1 standard.
  168. @item blank
  169. A space or tab character.
  170. @item builtin
  171. @cindex builtin
  172. A command that is implemented internally by the shell itself, rather
  173. than by an executable program somewhere in the file system.
  174. @item control operator
  175. @cindex control operator
  176. A @code{token} that performs a control function. It is a @code{newline}
  177. or one of the following:
  178. @samp{||}, @samp{&&}, @samp{&}, @samp{;}, @samp{;;}, @samp{;&}, @samp{;;&},
  179. @samp{|}, @samp{|&}, @samp{(}, or @samp{)}.
  180. @item exit status
  181. @cindex exit status
  182. The value returned by a command to its caller. The value is restricted
  183. to eight bits, so the maximum value is 255.
  184. @item field
  185. @cindex field
  186. A unit of text that is the result of one of the shell expansions. After
  187. expansion, when executing a command, the resulting fields are used as
  188. the command name and arguments.
  189. @item filename
  190. @cindex filename
  191. A string of characters used to identify a file.
  192. @item job
  193. @cindex job
  194. A set of processes comprising a pipeline, and any processes descended
  195. from it, that are all in the same process group.
  196. @item job control
  197. @cindex job control
  198. A mechanism by which users can selectively stop (suspend) and restart
  199. (resume) execution of processes.
  200. @item metacharacter
  201. @cindex metacharacter
  202. A character that, when unquoted, separates words. A metacharacter is
  203. a @code{space}, @code{tab}, @code{newline}, or one of the following characters:
  204. @samp{|}, @samp{&}, @samp{;}, @samp{(}, @samp{)}, @samp{<}, or
  205. @samp{>}.
  206. @item name
  207. @cindex name
  208. @cindex identifier
  209. A @code{word} consisting solely of letters, numbers, and underscores,
  210. and beginning with a letter or underscore. @code{Name}s are used as
  211. shell variable and function names.
  212. Also referred to as an @code{identifier}.
  213. @item operator
  214. @cindex operator, shell
  215. A @code{control operator} or a @code{redirection operator}.
  216. @xref{Redirections}, for a list of redirection operators.
  217. Operators contain at least one unquoted @code{metacharacter}.
  218. @item process group
  219. @cindex process group
  220. A collection of related processes each having the same process
  221. group @sc{id}.
  222. @item process group ID
  223. @cindex process group ID
  224. A unique identifier that represents a @code{process group}
  225. during its lifetime.
  226. @item reserved word
  227. @cindex reserved word
  228. A @code{word} that has a special meaning to the shell. Most reserved
  229. words introduce shell flow control constructs, such as @code{for} and
  230. @code{while}.
  231. @item return status
  232. @cindex return status
  233. A synonym for @code{exit status}.
  234. @item signal
  235. @cindex signal
  236. A mechanism by which a process may be notified by the kernel
  237. of an event occurring in the system.
  238. @item special builtin
  239. @cindex special builtin
  240. A shell builtin command that has been classified as special by the
  241. @sc{posix} standard.
  242. @item token
  243. @cindex token
  244. A sequence of characters considered a single unit by the shell.
  245. It is either a @code{word} or an @code{operator}.
  246. @item word
  247. @cindex word
  248. A sequence of characters treated as a unit by the shell.
  249. Words may not include unquoted @code{metacharacters}.
  250. @end table
  251. @node Basic Shell Features
  252. @chapter Basic Shell Features
  253. @cindex Bourne shell
  254. Bash is an acronym for @samp{Bourne-Again SHell}.
  255. The Bourne shell is
  256. the traditional Unix shell originally written by Stephen Bourne.
  257. All of the Bourne shell builtin commands are available in Bash,
  258. The rules for evaluation and quoting are taken from the @sc{posix}
  259. specification for the `standard' Unix shell.
  260. This chapter briefly summarizes the shell's `building blocks':
  261. commands, control structures, shell functions, shell @i{parameters},
  262. shell expansions,
  263. @i{redirections}, which are a way to direct input and output from
  264. and to named files, and how the shell executes commands.
  265. @menu
  266. * Shell Syntax:: What your input means to the shell.
  267. * Shell Commands:: The types of commands you can use.
  268. * Shell Functions:: Grouping commands by name.
  269. * Shell Parameters:: How the shell stores values.
  270. * Shell Expansions:: How Bash expands parameters and the various
  271. expansions available.
  272. * Redirections:: A way to control where input and output go.
  273. * Executing Commands:: What happens when you run a command.
  274. * Shell Scripts:: Executing files of shell commands.
  275. @end menu
  276. @node Shell Syntax
  277. @section Shell Syntax
  278. @menu
  279. * Shell Operation:: The basic operation of the shell.
  280. * Quoting:: How to remove the special meaning from characters.
  281. * Comments:: How to specify comments.
  282. @end menu
  283. When the shell reads input, it proceeds through a
  284. sequence of operations. If the input indicates the beginning of a
  285. comment, the shell ignores the comment symbol (@samp{#}), and the rest
  286. of that line.
  287. Otherwise, roughly speaking, the shell reads its input and
  288. divides the input into words and operators, employing the quoting rules
  289. to select which meanings to assign various words and characters.
  290. The shell then parses these tokens into commands and other constructs,
  291. removes the special meaning of certain words or characters, expands
  292. others, redirects input and output as needed, executes the specified
  293. command, waits for the command's exit status, and makes that exit status
  294. available for further inspection or processing.
  295. @node Shell Operation
  296. @subsection Shell Operation
  297. The following is a brief description of the shell's operation when it
  298. reads and executes a command. Basically, the shell does the
  299. following:
  300. @enumerate
  301. @item
  302. Reads its input from a file (@pxref{Shell Scripts}), from a string
  303. supplied as an argument to the @option{-c} invocation option
  304. (@pxref{Invoking Bash}), or from the user's terminal.
  305. @item
  306. Breaks the input into words and operators, obeying the quoting rules
  307. described in @ref{Quoting}. These tokens are separated by
  308. @code{metacharacters}. Alias expansion is performed by this step
  309. (@pxref{Aliases}).
  310. @item
  311. Parses the tokens into simple and compound commands
  312. (@pxref{Shell Commands}).
  313. @item
  314. Performs the various shell expansions (@pxref{Shell Expansions}), breaking
  315. the expanded tokens into lists of filenames (@pxref{Filename Expansion})
  316. and commands and arguments.
  317. @item
  318. Performs any necessary redirections (@pxref{Redirections}) and removes
  319. the redirection operators and their operands from the argument list.
  320. @item
  321. Executes the command (@pxref{Executing Commands}).
  322. @item
  323. Optionally waits for the command to complete and collects its exit
  324. status (@pxref{Exit Status}).
  325. @end enumerate
  326. @node Quoting
  327. @subsection Quoting
  328. @cindex quoting
  329. @menu
  330. * Escape Character:: How to remove the special meaning from a single
  331. character.
  332. * Single Quotes:: How to inhibit all interpretation of a sequence
  333. of characters.
  334. * Double Quotes:: How to suppress most of the interpretation of a
  335. sequence of characters.
  336. * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
  337. * Locale Translation:: How to translate strings into different languages.
  338. @end menu
  339. Quoting is used to remove the special meaning of certain
  340. characters or words to the shell. Quoting can be used to
  341. disable special treatment for special characters, to prevent
  342. reserved words from being recognized as such, and to prevent
  343. parameter expansion.
  344. Each of the shell metacharacters (@pxref{Definitions})
  345. has special meaning to the shell and must be quoted if it is to
  346. represent itself.
  347. When the command history expansion facilities are being used
  348. (@pxref{History Interaction}), the
  349. @var{history expansion} character, usually @samp{!}, must be quoted
  350. to prevent history expansion. @xref{Bash History Facilities}, for
  351. more details concerning history expansion.
  352. There are three quoting mechanisms: the
  353. @var{escape character}, single quotes, and double quotes.
  354. @node Escape Character
  355. @subsubsection Escape Character
  356. A non-quoted backslash @samp{\} is the Bash escape character.
  357. It preserves the literal value of the next character that follows,
  358. with the exception of @code{newline}. If a @code{\newline} pair
  359. appears, and the backslash itself is not quoted, the @code{\newline}
  360. is treated as a line continuation (that is, it is removed from
  361. the input stream and effectively ignored).
  362. @node Single Quotes
  363. @subsubsection Single Quotes
  364. Enclosing characters in single quotes (@samp{'}) preserves the literal value
  365. of each character within the quotes. A single quote may not occur
  366. between single quotes, even when preceded by a backslash.
  367. @node Double Quotes
  368. @subsubsection Double Quotes
  369. Enclosing characters in double quotes (@samp{"}) preserves the literal value
  370. of all characters within the quotes, with the exception of
  371. @samp{$}, @samp{`}, @samp{\},
  372. and, when history expansion is enabled, @samp{!}.
  373. When the shell is in
  374. @sc{posix} mode (@pxref{Bash POSIX Mode}),
  375. the @samp{!} has no special meaning
  376. within double quotes, even when history expansion is enabled.
  377. The characters @samp{$} and @samp{`}
  378. retain their special meaning within double quotes (@pxref{Shell Expansions}).
  379. The backslash retains its special meaning only when followed by one of
  380. the following characters:
  381. @samp{$}, @samp{`}, @samp{"}, @samp{\}, or @code{newline}.
  382. Within double quotes, backslashes that are followed by one of these
  383. characters are removed. Backslashes preceding characters without a
  384. special meaning are left unmodified.
  385. A double quote may be quoted within double quotes by preceding it with
  386. a backslash.
  387. If enabled, history expansion will be performed unless an @samp{!}
  388. appearing in double quotes is escaped using a backslash.
  389. The backslash preceding the @samp{!} is not removed.
  390. The special parameters @samp{*} and @samp{@@} have special meaning
  391. when in double quotes (@pxref{Shell Parameter Expansion}).
  392. @node ANSI-C Quoting
  393. @subsubsection ANSI-C Quoting
  394. @cindex quoting, ANSI
  395. Words of the form @code{$'@var{string}'} are treated specially. The
  396. word expands to @var{string}, with backslash-escaped characters replaced
  397. as specified by the ANSI C standard. Backslash escape sequences, if
  398. present, are decoded as follows:
  399. @table @code
  400. @item \a
  401. alert (bell)
  402. @item \b
  403. backspace
  404. @item \e
  405. @itemx \E
  406. an escape character (not ANSI C)
  407. @item \f
  408. form feed
  409. @item \n
  410. newline
  411. @item \r
  412. carriage return
  413. @item \t
  414. horizontal tab
  415. @item \v
  416. vertical tab
  417. @item \\
  418. backslash
  419. @item \'
  420. single quote
  421. @item \"
  422. double quote
  423. @item \?
  424. question mark
  425. @item \@var{nnn}
  426. the eight-bit character whose value is the octal value @var{nnn}
  427. (one to three digits)
  428. @item \x@var{HH}
  429. the eight-bit character whose value is the hexadecimal value @var{HH}
  430. (one or two hex digits)
  431. @item \u@var{HHHH}
  432. the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
  433. @var{HHHH} (one to four hex digits)
  434. @item \U@var{HHHHHHHH}
  435. the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
  436. @var{HHHHHHHH} (one to eight hex digits)
  437. @item \c@var{x}
  438. a control-@var{x} character
  439. @end table
  440. @noindent
  441. The expanded result is single-quoted, as if the dollar sign had not
  442. been present.
  443. @node Locale Translation
  444. @subsubsection Locale-Specific Translation
  445. @cindex localization
  446. @cindex internationalization
  447. @cindex native languages
  448. @cindex translation, native languages
  449. A double-quoted string preceded by a dollar sign (@samp{$}) will cause
  450. the string to be translated according to the current locale.
  451. If the current locale is @code{C} or @code{POSIX}, the dollar sign
  452. is ignored.
  453. If the string is translated and replaced, the replacement is
  454. double-quoted.
  455. @vindex LC_MESSAGES
  456. @vindex TEXTDOMAIN
  457. @vindex TEXTDOMAINDIR
  458. Some systems use the message catalog selected by the @env{LC_MESSAGES}
  459. shell variable. Others create the name of the message catalog from the
  460. value of the @env{TEXTDOMAIN} shell variable, possibly adding a
  461. suffix of @samp{.mo}. If you use the @env{TEXTDOMAIN} variable, you
  462. may need to set the @env{TEXTDOMAINDIR} variable to the location of
  463. the message catalog files. Still others use both variables in this
  464. fashion:
  465. @env{TEXTDOMAINDIR}/@env{LC_MESSAGES}/LC_MESSAGES/@env{TEXTDOMAIN}.mo.
  466. @node Comments
  467. @subsection Comments
  468. @cindex comments, shell
  469. In a non-interactive shell, or an interactive shell in which the
  470. @code{interactive_comments} option to the @code{shopt}
  471. builtin is enabled (@pxref{The Shopt Builtin}),
  472. a word beginning with @samp{#}
  473. causes that word and all remaining characters on that line to
  474. be ignored. An interactive shell without the @code{interactive_comments}
  475. option enabled does not allow comments. The @code{interactive_comments}
  476. option is on by default in interactive shells.
  477. @xref{Interactive Shells}, for a description of what makes
  478. a shell interactive.
  479. @node Shell Commands
  480. @section Shell Commands
  481. @cindex commands, shell
  482. A simple shell command such as @code{echo a b c} consists of the command
  483. itself followed by arguments, separated by spaces.
  484. More complex shell commands are composed of simple commands arranged together
  485. in a variety of ways: in a pipeline in which the output of one command
  486. becomes the input of a second, in a loop or conditional construct, or in
  487. some other grouping.
  488. @menu
  489. * Simple Commands:: The most common type of command.
  490. * Pipelines:: Connecting the input and output of several
  491. commands.
  492. * Lists:: How to execute commands sequentially.
  493. * Compound Commands:: Shell commands for control flow.
  494. * Coprocesses:: Two-way communication between commands.
  495. * GNU Parallel:: Running commands in parallel.
  496. @end menu
  497. @node Simple Commands
  498. @subsection Simple Commands
  499. @cindex commands, simple
  500. A simple command is the kind of command encountered most often.
  501. It's just a sequence of words separated by @code{blank}s, terminated
  502. by one of the shell's control operators (@pxref{Definitions}). The
  503. first word generally specifies a command to be executed, with the
  504. rest of the words being that command's arguments.
  505. The return status (@pxref{Exit Status}) of a simple command is
  506. its exit status as provided
  507. by the @sc{posix} 1003.1 @code{waitpid} function, or 128+@var{n} if
  508. the command was terminated by signal @var{n}.
  509. @node Pipelines
  510. @subsection Pipelines
  511. @cindex pipeline
  512. @cindex commands, pipelines
  513. A @code{pipeline} is a sequence of one or more commands separated by
  514. one of the control operators @samp{|} or @samp{|&}.
  515. @rwindex time
  516. @rwindex !
  517. @cindex command timing
  518. The format for a pipeline is
  519. @example
  520. [time [-p]] [!] @var{command1} [ | or |& @var{command2} ] @dots{}
  521. @end example
  522. @noindent
  523. The output of each command in the pipeline is connected via a pipe
  524. to the input of the next command.
  525. That is, each command reads the previous command's output. This
  526. connection is performed before any redirections specified by the
  527. command.
  528. If @samp{|&} is used, @var{command1}'s standard error, in addition to
  529. its standard output, is connected to
  530. @var{command2}'s standard input through the pipe;
  531. it is shorthand for @code{2>&1 |}.
  532. This implicit redirection of the standard error to the standard output is
  533. performed after any redirections specified by the command.
  534. The reserved word @code{time} causes timing statistics
  535. to be printed for the pipeline once it finishes.
  536. The statistics currently consist of elapsed (wall-clock) time and
  537. user and system time consumed by the command's execution.
  538. The @option{-p} option changes the output format to that specified
  539. by @sc{posix}.
  540. When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}),
  541. it does not recognize @code{time} as a reserved word if the next
  542. token begins with a @samp{-}.
  543. The @env{TIMEFORMAT} variable may be set to a format string that
  544. specifies how the timing information should be displayed.
  545. @xref{Bash Variables}, for a description of the available formats.
  546. The use of @code{time} as a reserved word permits the timing of
  547. shell builtins, shell functions, and pipelines. An external
  548. @code{time} command cannot time these easily.
  549. When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}), @code{time}
  550. may be followed by a newline. In this case, the shell displays the
  551. total user and system time consumed by the shell and its children.
  552. The @env{TIMEFORMAT} variable may be used to specify the format of
  553. the time information.
  554. If the pipeline is not executed asynchronously (@pxref{Lists}), the
  555. shell waits for all commands in the pipeline to complete.
  556. Each command in a pipeline is executed in its own subshell
  557. (@pxref{Command Execution Environment}). The exit
  558. status of a pipeline is the exit status of the last command in the
  559. pipeline, unless the @code{pipefail} option is enabled
  560. (@pxref{The Set Builtin}).
  561. If @code{pipefail} is enabled, the pipeline's return status is the
  562. value of the last (rightmost) command to exit with a non-zero status,
  563. or zero if all commands exit successfully.
  564. If the reserved word @samp{!} precedes the pipeline, the
  565. exit status is the logical negation of the exit status as described
  566. above.
  567. The shell waits for all commands in the pipeline to terminate before
  568. returning a value.
  569. @node Lists
  570. @subsection Lists of Commands
  571. @cindex commands, lists
  572. A @code{list} is a sequence of one or more pipelines separated by one
  573. of the operators @samp{;}, @samp{&}, @samp{&&}, or @samp{||},
  574. and optionally terminated by one of @samp{;}, @samp{&}, or a
  575. @code{newline}.
  576. Of these list operators, @samp{&&} and @samp{||}
  577. have equal precedence, followed by @samp{;} and @samp{&},
  578. which have equal precedence.
  579. A sequence of one or more newlines may appear in a @code{list}
  580. to delimit commands, equivalent to a semicolon.
  581. If a command is terminated by the control operator @samp{&},
  582. the shell executes the command asynchronously in a subshell.
  583. This is known as executing the command in the @var{background}.
  584. The shell does not wait for the command to finish, and the return
  585. status is 0 (true).
  586. When job control is not active (@pxref{Job Control}),
  587. the standard input for asynchronous commands, in the absence of any
  588. explicit redirections, is redirected from @code{/dev/null}.
  589. Commands separated by a @samp{;} are executed sequentially; the shell
  590. waits for each command to terminate in turn. The return status is the
  591. exit status of the last command executed.
  592. @sc{and} and @sc{or} lists are sequences of one or more pipelines
  593. separated by the control operators @samp{&&} and @samp{||},
  594. respectively. @sc{and} and @sc{or} lists are executed with left
  595. associativity.
  596. An @sc{and} list has the form
  597. @example
  598. @var{command1} && @var{command2}
  599. @end example
  600. @noindent
  601. @var{command2} is executed if, and only if, @var{command1}
  602. returns an exit status of zero.
  603. An @sc{or} list has the form
  604. @example
  605. @var{command1} || @var{command2}
  606. @end example
  607. @noindent
  608. @var{command2} is executed if, and only if, @var{command1}
  609. returns a non-zero exit status.
  610. The return status of
  611. @sc{and} and @sc{or} lists is the exit status of the last command
  612. executed in the list.
  613. @node Compound Commands
  614. @subsection Compound Commands
  615. @cindex commands, compound
  616. @menu
  617. * Looping Constructs:: Shell commands for iterative action.
  618. * Conditional Constructs:: Shell commands for conditional execution.
  619. * Command Grouping:: Ways to group commands.
  620. @end menu
  621. Compound commands are the shell programming constructs.
  622. Each construct begins with a reserved word or control operator and is
  623. terminated by a corresponding reserved word or operator.
  624. Any redirections (@pxref{Redirections}) associated with a compound command
  625. apply to all commands within that compound command unless explicitly overridden.
  626. In most cases a list of commands in a compound command's description may be
  627. separated from the rest of the command by one or more newlines, and may be
  628. followed by a newline in place of a semicolon.
  629. Bash provides looping constructs, conditional commands, and mechanisms
  630. to group commands and execute them as a unit.
  631. @node Looping Constructs
  632. @subsubsection Looping Constructs
  633. @cindex commands, looping
  634. Bash supports the following looping constructs.
  635. Note that wherever a @samp{;} appears in the description of a
  636. command's syntax, it may be replaced with one or more newlines.
  637. @table @code
  638. @item until
  639. @rwindex until
  640. @rwindex do
  641. @rwindex done
  642. The syntax of the @code{until} command is:
  643. @example
  644. until @var{test-commands}; do @var{consequent-commands}; done
  645. @end example
  646. Execute @var{consequent-commands} as long as
  647. @var{test-commands} has an exit status which is not zero.
  648. The return status is the exit status of the last command executed
  649. in @var{consequent-commands}, or zero if none was executed.
  650. @item while
  651. @rwindex while
  652. The syntax of the @code{while} command is:
  653. @example
  654. while @var{test-commands}; do @var{consequent-commands}; done
  655. @end example
  656. Execute @var{consequent-commands} as long as
  657. @var{test-commands} has an exit status of zero.
  658. The return status is the exit status of the last command executed
  659. in @var{consequent-commands}, or zero if none was executed.
  660. @item for
  661. @rwindex for
  662. The syntax of the @code{for} command is:
  663. @example
  664. for @var{name} [ [in [@var{words} @dots{}] ] ; ] do @var{commands}; done
  665. @end example
  666. Expand @var{words}, and execute @var{commands} once for each member
  667. in the resultant list, with @var{name} bound to the current member.
  668. If @samp{in @var{words}} is not present, the @code{for} command
  669. executes the @var{commands} once for each positional parameter that is
  670. set, as if @samp{in "$@@"} had been specified
  671. (@pxref{Special Parameters}).
  672. The return status is the exit status of the last command that executes.
  673. If there are no items in the expansion of @var{words}, no commands are
  674. executed, and the return status is zero.
  675. An alternate form of the @code{for} command is also supported:
  676. @example
  677. for (( @var{expr1} ; @var{expr2} ; @var{expr3} )) ; do @var{commands} ; done
  678. @end example
  679. First, the arithmetic expression @var{expr1} is evaluated according
  680. to the rules described below (@pxref{Shell Arithmetic}).
  681. The arithmetic expression @var{expr2} is then evaluated repeatedly
  682. until it evaluates to zero.
  683. Each time @var{expr2} evaluates to a non-zero value, @var{commands} are
  684. executed and the arithmetic expression @var{expr3} is evaluated.
  685. If any expression is omitted, it behaves as if it evaluates to 1.
  686. The return value is the exit status of the last command in @var{commands}
  687. that is executed, or false if any of the expressions is invalid.
  688. @end table
  689. The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins})
  690. may be used to control loop execution.
  691. @node Conditional Constructs
  692. @subsubsection Conditional Constructs
  693. @cindex commands, conditional
  694. @table @code
  695. @item if
  696. @rwindex if
  697. @rwindex then
  698. @rwindex else
  699. @rwindex elif
  700. @rwindex fi
  701. The syntax of the @code{if} command is:
  702. @example
  703. if @var{test-commands}; then
  704. @var{consequent-commands};
  705. [elif @var{more-test-commands}; then
  706. @var{more-consequents};]
  707. [else @var{alternate-consequents};]
  708. fi
  709. @end example
  710. The @var{test-commands} list is executed, and if its return status is zero,
  711. the @var{consequent-commands} list is executed.
  712. If @var{test-commands} returns a non-zero status, each @code{elif} list
  713. is executed in turn, and if its exit status is zero,
  714. the corresponding @var{more-consequents} is executed and the
  715. command completes.
  716. If @samp{else @var{alternate-consequents}} is present, and
  717. the final command in the final @code{if} or @code{elif} clause
  718. has a non-zero exit status, then @var{alternate-consequents} is executed.
  719. The return status is the exit status of the last command executed, or
  720. zero if no condition tested true.
  721. @item case
  722. @rwindex case
  723. @rwindex in
  724. @rwindex esac
  725. The syntax of the @code{case} command is:
  726. @example
  727. case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac
  728. @end example
  729. @code{case} will selectively execute the @var{command-list} corresponding to
  730. the first @var{pattern} that matches @var{word}.
  731. If the @code{nocasematch} shell option
  732. (see the description of @code{shopt} in @ref{The Shopt Builtin})
  733. is enabled, the match is performed without regard to the case
  734. of alphabetic characters.
  735. The @samp{|} is used to separate multiple patterns, and the @samp{)}
  736. operator terminates a pattern list.
  737. A list of patterns and an associated command-list is known
  738. as a @var{clause}.
  739. Each clause must be terminated with @samp{;;}, @samp{;&}, or @samp{;;&}.
  740. The @var{word} undergoes tilde expansion, parameter expansion, command
  741. substitution, arithmetic expansion, and quote removal before matching is
  742. attempted. Each @var{pattern} undergoes tilde expansion, parameter
  743. expansion, command substitution, and arithmetic expansion.
  744. There may be an arbitrary number of @code{case} clauses, each terminated
  745. by a @samp{;;}, @samp{;&}, or @samp{;;&}.
  746. The first pattern that matches determines the
  747. command-list that is executed.
  748. It's a common idiom to use @samp{*} as the final pattern to define the
  749. default case, since that pattern will always match.
  750. Here is an example using @code{case} in a script that could be used to
  751. describe one interesting feature of an animal:
  752. @example
  753. echo -n "Enter the name of an animal: "
  754. read ANIMAL
  755. echo -n "The $ANIMAL has "
  756. case $ANIMAL in
  757. horse | dog | cat) echo -n "four";;
  758. man | kangaroo ) echo -n "two";;
  759. *) echo -n "an unknown number of";;
  760. esac
  761. echo " legs."
  762. @end example
  763. @noindent
  764. If the @samp{;;} operator is used, no subsequent matches are attempted after
  765. the first pattern match.
  766. Using @samp{;&} in place of @samp{;;} causes execution to continue with
  767. the @var{command-list} associated with the next clause, if any.
  768. Using @samp{;;&} in place of @samp{;;} causes the shell to test the patterns
  769. in the next clause, if any, and execute any associated @var{command-list}
  770. on a successful match.
  771. The return status is zero if no @var{pattern} is matched. Otherwise, the
  772. return status is the exit status of the @var{command-list} executed.
  773. @item select
  774. @rwindex select
  775. The @code{select} construct allows the easy generation of menus.
  776. It has almost the same syntax as the @code{for} command:
  777. @example
  778. select @var{name} [in @var{words} @dots{}]; do @var{commands}; done
  779. @end example
  780. The list of words following @code{in} is expanded, generating a list
  781. of items. The set of expanded words is printed on the standard
  782. error output stream, each preceded by a number. If the
  783. @samp{in @var{words}} is omitted, the positional parameters are printed,
  784. as if @samp{in "$@@"} had been specified.
  785. The @env{PS3} prompt is then displayed and a line is read from the
  786. standard input.
  787. If the line consists of a number corresponding to one of the displayed
  788. words, then the value of @var{name} is set to that word.
  789. If the line is empty, the words and prompt are displayed again.
  790. If @code{EOF} is read, the @code{select} command completes.
  791. Any other value read causes @var{name} to be set to null.
  792. The line read is saved in the variable @env{REPLY}.
  793. The @var{commands} are executed after each selection until a
  794. @code{break} command is executed, at which
  795. point the @code{select} command completes.
  796. Here is an example that allows the user to pick a filename from the
  797. current directory, and displays the name and index of the file
  798. selected.
  799. @example
  800. select fname in *;
  801. do
  802. echo you picked $fname \($REPLY\)
  803. break;
  804. done
  805. @end example
  806. @item ((@dots{}))
  807. @example
  808. (( @var{expression} ))
  809. @end example
  810. The arithmetic @var{expression} is evaluated according to the rules
  811. described below (@pxref{Shell Arithmetic}).
  812. If the value of the expression is non-zero, the return status is 0;
  813. otherwise the return status is 1. This is exactly equivalent to
  814. @example
  815. let "@var{expression}"
  816. @end example
  817. @noindent
  818. @xref{Bash Builtins}, for a full description of the @code{let} builtin.
  819. @item [[@dots{}]]
  820. @rwindex [[
  821. @rwindex ]]
  822. @example
  823. [[ @var{expression} ]]
  824. @end example
  825. Return a status of 0 or 1 depending on the evaluation of
  826. the conditional expression @var{expression}.
  827. Expressions are composed of the primaries described below in
  828. @ref{Bash Conditional Expressions}.
  829. Word splitting and filename expansion are not performed on the words
  830. between the @code{[[} and @code{]]}; tilde expansion, parameter and
  831. variable expansion, arithmetic expansion, command substitution, process
  832. substitution, and quote removal are performed.
  833. Conditional operators such as @samp{-f} must be unquoted to be recognized
  834. as primaries.
  835. When used with @code{[[}, the @samp{<} and @samp{>} operators sort
  836. lexicographically using the current locale.
  837. When the @samp{==} and @samp{!=} operators are used, the string to the
  838. right of the operator is considered a pattern and matched according
  839. to the rules described below in @ref{Pattern Matching},
  840. as if the @code{extglob} shell option were enabled.
  841. The @samp{=} operator is identical to @samp{==}.
  842. If the @code{nocasematch} shell option
  843. (see the description of @code{shopt} in @ref{The Shopt Builtin})
  844. is enabled, the match is performed without regard to the case
  845. of alphabetic characters.
  846. The return value is 0 if the string matches (@samp{==}) or does not
  847. match (@samp{!=})the pattern, and 1 otherwise.
  848. Any part of the pattern may be quoted to force the quoted portion
  849. to be matched as a string.
  850. An additional binary operator, @samp{=~}, is available, with the same
  851. precedence as @samp{==} and @samp{!=}.
  852. When it is used, the string to the right of the operator is considered
  853. an extended regular expression and matched accordingly (as in @i{regex}3)).
  854. The return value is 0 if the string matches
  855. the pattern, and 1 otherwise.
  856. If the regular expression is syntactically incorrect, the conditional
  857. expression's return value is 2.
  858. If the @code{nocasematch} shell option
  859. (see the description of @code{shopt} in @ref{The Shopt Builtin})
  860. is enabled, the match is performed without regard to the case
  861. of alphabetic characters.
  862. Any part of the pattern may be quoted to force the quoted portion
  863. to be matched as a string.
  864. Bracket expressions in regular expressions must be treated carefully,
  865. since normal quoting characters lose their meanings between brackets.
  866. If the pattern is stored in a shell variable, quoting the variable
  867. expansion forces the entire pattern to be matched as a string.
  868. Substrings matched by parenthesized subexpressions within the regular
  869. expression are saved in the array variable @code{BASH_REMATCH}.
  870. The element of @code{BASH_REMATCH} with index 0 is the portion of the string
  871. matching the entire regular expression.
  872. The element of @code{BASH_REMATCH} with index @var{n} is the portion of the
  873. string matching the @var{n}th parenthesized subexpression.
  874. For example, the following will match a line
  875. (stored in the shell variable @var{line})
  876. if there is a sequence of characters in the value consisting of
  877. any number, including zero, of
  878. space characters, zero or one instances of @samp{a}, then a @samp{b}:
  879. @example
  880. [[ $line =~ [[:space:]]*(a)?b ]]
  881. @end example
  882. @noindent
  883. That means values like @samp{aab} and @samp{ aaaaaab} will match, as
  884. will a line containing a @samp{b} anywhere in its value.
  885. Storing the regular expression in a shell variable is often a useful
  886. way to avoid problems with quoting characters that are special to the
  887. shell.
  888. It is sometimes difficult to specify a regular expression literally
  889. without using quotes, or to keep track of the quoting used by regular
  890. expressions while paying attention to the shell's quote removal.
  891. Using a shell variable to store the pattern decreases these problems.
  892. For example, the following is equivalent to the above:
  893. @example
  894. pattern='[[:space:]]*(a)?b'
  895. [[ $line =~ $pattern ]]
  896. @end example
  897. @noindent
  898. If you want to match a character that's special to the regular expression
  899. grammar, it has to be quoted to remove its special meaning.
  900. This means that in the pattern @samp{xxx.txt}, the @samp{.} matches any
  901. character in the string (its usual regular expression meaning), but in the
  902. pattern @samp{"xxx.txt"} it can only match a literal @samp{.}.
  903. Shell programmers should take special care with backslashes, since backslashes
  904. are used both by the shell and regular expressions to remove the special
  905. meaning from the following character.
  906. The following two sets of commands are @emph{not} equivalent:
  907. @example
  908. pattern='\.'
  909. [[ . =~ $pattern ]]
  910. [[ . =~ \. ]]
  911. [[ . =~ "$pattern" ]]
  912. [[ . =~ '\.' ]]
  913. @end example
  914. @noindent
  915. The first two matches will succeed, but the second two will not, because
  916. in the second two the backslash will be part of the pattern to be matched.
  917. In the first two examples, the backslash removes the special meaning from
  918. @samp{.}, so the literal @samp{.} matches.
  919. If the string in the first examples were anything other than @samp{.}, say
  920. @samp{a}, the pattern would not match, because the quoted @samp{.} in the
  921. pattern loses its special meaning of matching any single character.
  922. Expressions may be combined using the following operators, listed
  923. in decreasing order of precedence:
  924. @table @code
  925. @item ( @var{expression} )
  926. Returns the value of @var{expression}.
  927. This may be used to override the normal precedence of operators.
  928. @item ! @var{expression}
  929. True if @var{expression} is false.
  930. @item @var{expression1} && @var{expression2}
  931. True if both @var{expression1} and @var{expression2} are true.
  932. @item @var{expression1} || @var{expression2}
  933. True if either @var{expression1} or @var{expression2} is true.
  934. @end table
  935. @noindent
  936. The @code{&&} and @code{||} operators do not evaluate @var{expression2} if the
  937. value of @var{expression1} is sufficient to determine the return
  938. value of the entire conditional expression.
  939. @end table
  940. @node Command Grouping
  941. @subsubsection Grouping Commands
  942. @cindex commands, grouping
  943. Bash provides two ways to group a list of commands to be executed
  944. as a unit. When commands are grouped, redirections may be applied
  945. to the entire command list. For example, the output of all the
  946. commands in the list may be redirected to a single stream.
  947. @table @code
  948. @item ()
  949. @example
  950. ( @var{list} )
  951. @end example
  952. Placing a list of commands between parentheses causes a subshell
  953. environment to be created (@pxref{Command Execution Environment}), and each
  954. of the commands in @var{list} to be executed in that subshell. Since the
  955. @var{list} is executed in a subshell, variable assignments do not remain in
  956. effect after the subshell completes.
  957. @item @{@}
  958. @rwindex @{
  959. @rwindex @}
  960. @example
  961. @{ @var{list}; @}
  962. @end example
  963. Placing a list of commands between curly braces causes the list to
  964. be executed in the current shell context. No subshell is created.
  965. The semicolon (or newline) following @var{list} is required.
  966. @end table
  967. In addition to the creation of a subshell, there is a subtle difference
  968. between these two constructs due to historical reasons. The braces
  969. are @code{reserved words}, so they must be separated from the @var{list}
  970. by @code{blank}s or other shell metacharacters.
  971. The parentheses are @code{operators}, and are
  972. recognized as separate tokens by the shell even if they are not separated
  973. from the @var{list} by whitespace.
  974. The exit status of both of these constructs is the exit status of
  975. @var{list}.
  976. @node Coprocesses
  977. @subsection Coprocesses
  978. @cindex coprocess
  979. A @code{coprocess} is a shell command preceded by the @code{coproc}
  980. reserved word.
  981. A coprocess is executed asynchronously in a subshell, as if the command
  982. had been terminated with the @samp{&} control operator, with a two-way pipe
  983. established between the executing shell and the coprocess.
  984. The format for a coprocess is:
  985. @example
  986. coproc [@var{NAME}] @var{command} [@var{redirections}]
  987. @end example
  988. @noindent
  989. This creates a coprocess named @var{NAME}.
  990. If @var{NAME} is not supplied, the default name is @var{COPROC}.
  991. @var{NAME} must not be supplied if @var{command} is a simple
  992. command (@pxref{Simple Commands}); otherwise, it is interpreted as
  993. the first word of the simple command.
  994. When the coprocess is executed, the shell creates an array variable
  995. (@pxref{Arrays})
  996. named @env{NAME} in the context of the executing shell.
  997. The standard output of @var{command}
  998. is connected via a pipe to a file descriptor in the executing shell,
  999. and that file descriptor is assigned to @env{NAME}[0].
  1000. The standard input of @var{command}
  1001. is connected via a pipe to a file descriptor in the executing shell,
  1002. and that file descriptor is assigned to @env{NAME}[1].
  1003. This pipe is established before any redirections specified by the
  1004. command (@pxref{Redirections}).
  1005. The file descriptors can be utilized as arguments to shell commands
  1006. and redirections using standard word expansions.
  1007. The file descriptors are not available in subshells.
  1008. The process ID of the shell spawned to execute the coprocess is
  1009. available as the value of the variable @env{NAME}_PID.
  1010. The @code{wait}
  1011. builtin command may be used to wait for the coprocess to terminate.
  1012. Since the coprocess is created as an asynchronous command,
  1013. the @code{coproc} command always returns success.
  1014. The return status of a coprocess is the exit status of @var{command}.
  1015. @node GNU Parallel
  1016. @subsection GNU Parallel
  1017. There are ways to run commands in parallel that are not built into Bash.
  1018. GNU Parallel is a tool to do just that.
  1019. GNU Parallel, as its name suggests, can be used to build and run commands
  1020. in parallel. You may run the same command with different arguments, whether
  1021. they are filenames, usernames, hostnames, or lines read from files. GNU
  1022. Parallel provides shorthand references to many of the most common operations
  1023. (input lines, various portions of the input line, different ways to specify
  1024. the input source, and so on). Parallel can replace @code{xargs} or feed
  1025. commands from its input sources to several different instances of Bash.
  1026. For a complete description, refer to the GNU Parallel documentation. A few
  1027. examples should provide a brief introduction to its use.
  1028. For example, it is easy to replace @code{xargs} to gzip all html files in the
  1029. current directory and its subdirectories:
  1030. @example
  1031. find . -type f -name '*.html' -print | parallel gzip
  1032. @end example
  1033. @noindent
  1034. If you need to protect special characters such as newlines in file names,
  1035. use find's @option{-print0} option and parallel's @option{-0} option.
  1036. You can use Parallel to move files from the current directory when the
  1037. number of files is too large to process with one @code{mv} invocation:
  1038. @example
  1039. ls | parallel mv @{@} destdir
  1040. @end example
  1041. As you can see, the @{@} is replaced with each line read from standard input.
  1042. While using @code{ls} will work in most instances, it is not sufficient to
  1043. deal with all filenames.
  1044. If you need to accommodate special characters in filenames, you can use
  1045. @example
  1046. find . -depth 1 \! -name '.*' -print0 | parallel -0 mv @{@} destdir
  1047. @end example
  1048. @noindent
  1049. as alluded to above.
  1050. This will run as many @code{mv} commands as there are files in the current
  1051. directory.
  1052. You can emulate a parallel @code{xargs} by adding the @option{-X} option:
  1053. @example
  1054. find . -depth 1 \! -name '.*' -print0 | parallel -0 -X mv @{@} destdir
  1055. @end example
  1056. GNU Parallel can replace certain common idioms that operate on lines read
  1057. from a file (in this case, filenames listed one per line):
  1058. @example
  1059. while IFS= read -r x; do
  1060. do-something1 "$x" "config-$x"
  1061. do-something2 < "$x"
  1062. done < file | process-output
  1063. @end example
  1064. @noindent
  1065. with a more compact syntax reminiscent of lambdas:
  1066. @example
  1067. cat list | parallel "do-something1 @{@} config-@{@} ; do-something2 < @{@}" | process-output
  1068. @end example
  1069. Parallel provides a built-in mechanism to remove filename extensions, which
  1070. lends itself to batch file transformations or renaming:
  1071. @example
  1072. ls *.gz | parallel -j+0 "zcat @{@} | bzip2 >@{.@}.bz2 && rm @{@}"
  1073. @end example
  1074. @noindent
  1075. This will recompress all files in the current directory with names ending
  1076. in .gz using bzip2, running one job per CPU (-j+0) in parallel.
  1077. (We use @code{ls} for brevity here; using @code{find} as above is more
  1078. robust in the face of filenames containing unexpected characters.)
  1079. Parallel can take arguments from the command line; the above can also be
  1080. written as
  1081. @example
  1082. parallel "zcat @{@} | bzip2 >@{.@}.bz2 && rm @{@}" ::: *.gz
  1083. @end example
  1084. If a command generates output, you may want to preserve the input order in
  1085. the output. For instance, the following command
  1086. @example
  1087. @{ echo foss.org.my ; echo debian.org; echo freenetproject.org; @} | parallel traceroute
  1088. @end example
  1089. @noindent
  1090. will display as output the traceroute invocation that finishes first.
  1091. Adding the @option{-k} option
  1092. @example
  1093. @{ echo foss.org.my ; echo debian.org; echo freenetproject.org; @} | parallel -k traceroute
  1094. @end example
  1095. @noindent
  1096. will ensure that the output of @code{traceroute foss.org.my} is displayed first.
  1097. Finally, Parallel can be used to run a sequence of shell commands in parallel,
  1098. similar to @samp{cat file | bash}.
  1099. It is not uncommon to take a list of filenames, create a series of shell
  1100. commands to operate on them, and feed that list of commnds to a shell.
  1101. Parallel can speed this up. Assuming that @file{file} contains a list of
  1102. shell commands, one per line,
  1103. @example
  1104. parallel -j 10 < file
  1105. @end example
  1106. @noindent
  1107. will evaluate the commands using the shell (since no explicit command is
  1108. supplied as an argument), in blocks of ten shell jobs at a time.
  1109. @node Shell Functions
  1110. @section Shell Functions
  1111. @cindex shell function
  1112. @cindex functions, shell
  1113. Shell functions are a way to group commands for later execution
  1114. using a single name for the group. They are executed just like
  1115. a "regular" command.
  1116. When the name of a shell function is used as a simple command name,
  1117. the list of commands associated with that function name is executed.
  1118. Shell functions are executed in the current
  1119. shell context; no new process is created to interpret them.
  1120. Functions are declared using this syntax:
  1121. @rwindex function
  1122. @example
  1123. @var{name} () @var{compound-command} [ @var{redirections} ]
  1124. @end example
  1125. or
  1126. @example
  1127. function @var{name} [()] @var{compound-command} [ @var{redirections} ]
  1128. @end example
  1129. This defines a shell function named @var{name}. The reserved
  1130. word @code{function} is optional.
  1131. If the @code{function} reserved
  1132. word is supplied, the parentheses are optional.
  1133. The @var{body} of the function is the compound command
  1134. @var{compound-command} (@pxref{Compound Commands}).
  1135. That command is usually a @var{list} enclosed between @{ and @}, but
  1136. may be any compound command listed above,
  1137. with one exception: If the @code{function} reserved word is used, but the
  1138. parentheses are not supplied, the braces are required.
  1139. @var{compound-command} is executed whenever @var{name} is specified as the
  1140. name of a command.
  1141. When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}),
  1142. @var{name} may not be the same as one of the special builtins
  1143. (@pxref{Special Builtins}).
  1144. Any redirections (@pxref{Redirections}) associated with the shell function
  1145. are performed when the function is executed.
  1146. A function definition may be deleted using the @option{-f} option to the
  1147. @code{unset} builtin (@pxref{Bourne Shell Builtins}).
  1148. The exit status of a function definition is zero unless a syntax error
  1149. occurs or a readonly function with the same name already exists.
  1150. When executed, the exit status of a function is the exit status of the
  1151. last command executed in the body.
  1152. Note that for historical reasons, in the most common usage the curly braces
  1153. that surround the body of the function must be separated from the body by
  1154. @code{blank}s or newlines.
  1155. This is because the braces are reserved words and are only recognized
  1156. as such when they are separated from the command list
  1157. by whitespace or another shell metacharacter.
  1158. Also, when using the braces, the @var{list} must be terminated by a semicolon,
  1159. a @samp{&}, or a newline.
  1160. When a function is executed, the arguments to the
  1161. function become the positional parameters
  1162. during its execution (@pxref{Positional Parameters}).
  1163. The special parameter @samp{#} that expands to the number of
  1164. positional parameters is updated to reflect the change.
  1165. Special parameter @code{0} is unchanged.
  1166. The first element of the @env{FUNCNAME} variable is set to the
  1167. name of the function while the function is executing.
  1168. All other aspects of the shell execution
  1169. environment are identical between a function and its caller
  1170. with these exceptions:
  1171. the @env{DEBUG} and @env{RETURN} traps
  1172. are not inherited unless the function has been given the
  1173. @code{trace} attribute using the @code{declare} builtin or
  1174. the @code{-o functrace} option has been enabled with
  1175. the @code{set} builtin,
  1176. (in which case all functions inherit the @env{DEBUG} and @env{RETURN} traps),
  1177. and the @env{ERR} trap is not inherited unless the @code{-o errtrace}
  1178. shell option has been enabled.
  1179. @xref{Bourne Shell Builtins}, for the description of the
  1180. @code{trap} builtin.
  1181. The @env{FUNCNEST} variable, if set to a numeric value greater
  1182. than 0, defines a maximum function nesting level. Function
  1183. invocations that exceed the limit cause the entire command to
  1184. abort.
  1185. If the builtin command @code{return}
  1186. is executed in a function, the function completes and
  1187. execution resumes with the next command after the function
  1188. call.
  1189. Any command associated with the @code{RETURN} trap is executed
  1190. before execution resumes.
  1191. When a function completes, the values of the
  1192. positional parameters and the special parameter @samp{#}
  1193. are restored to the values they had prior to the function's
  1194. execution. If a numeric argument is given to @code{return},
  1195. that is the function's return status; otherwise the function's
  1196. return status is the exit status of the last command executed
  1197. before the @code{return}.
  1198. Variables local to the function may be declared with the
  1199. @code{local} builtin. These variables are visible only to
  1200. the function and the commands it invokes.
  1201. Function names and definitions may be listed with the
  1202. @option{-f} option to the @code{declare} (@code{typeset})
  1203. builtin command (@pxref{Bash Builtins}).
  1204. The @option{-F} option to @code{declare} or @code{typeset}
  1205. will list the function names only
  1206. (and optionally the source file and line number, if the @code{extdebug}
  1207. shell option is enabled).
  1208. Functions may be exported so that subshells
  1209. automatically have them defined with the
  1210. @option{-f} option to the @code{export} builtin
  1211. (@pxref{Bourne Shell Builtins}).
  1212. Note that shell functions and variables with the same name may result
  1213. in multiple identically-named entries in the environment passed to the
  1214. shell's children.
  1215. Care should be taken in cases where this may cause a problem.
  1216. Functions may be recursive.
  1217. The @code{FUNCNEST} variable may be used to limit the depth of the
  1218. function call stack and restrict the number of function invocations.
  1219. By default, no limit is placed on the number of recursive calls.
  1220. @node Shell Parameters
  1221. @section Shell Parameters
  1222. @cindex parameters
  1223. @cindex variable, shell
  1224. @cindex shell variable
  1225. @menu
  1226. * Positional Parameters:: The shell's command-line arguments.
  1227. * Special Parameters:: Parameters denoted by special characters.
  1228. @end menu
  1229. A @var{parameter} is an entity that stores values.
  1230. It can be a @code{name}, a number, or one of the special characters
  1231. listed below.
  1232. A @var{variable} is a parameter denoted by a @code{name}.
  1233. A variable has a @var{value} and zero or more @var{attributes}.
  1234. Attributes are assigned using the @code{declare} builtin command
  1235. (see the description of the @code{declare} builtin in @ref{Bash Builtins}).
  1236. A parameter is set if it has been assigned a value. The null string is
  1237. a valid value. Once a variable is set, it may be unset only by using
  1238. the @code{unset} builtin command.
  1239. A variable may be assigned to by a statement of the form
  1240. @example
  1241. @var{name}=[@var{value}]
  1242. @end example
  1243. @noindent
  1244. If @var{value}
  1245. is not given, the variable is assigned the null string. All
  1246. @var{value}s undergo tilde expansion, parameter and variable expansion,
  1247. command substitution, arithmetic expansion, and quote
  1248. removal (detailed below). If the variable has its @code{integer}
  1249. attribute set, then @var{value}
  1250. is evaluated as an arithmetic expression even if the @code{$((@dots{}))}
  1251. expansion is not used (@pxref{Arithmetic Expansion}).
  1252. Word splitting is not performed, with the exception
  1253. of @code{"$@@"} as explained below.
  1254. Filename expansion is not performed.
  1255. Assignment statements may also appear as arguments to the
  1256. @code{alias},
  1257. @code{declare}, @code{typeset}, @code{export}, @code{readonly},
  1258. and @code{local} builtin commands (@var{declaration} commands).
  1259. When in @sc{posix} mode (@pxref{Bash POSIX Mode}), these builtins may appear
  1260. in a command after one or more instances of the @code{command} builtin
  1261. and retain these assignment statement properties.
  1262. In the context where an assignment statement is assigning a value
  1263. to a shell variable or array index (@pxref{Arrays}), the @samp{+=}
  1264. operator can be used to
  1265. append to or add to the variable's previous value.
  1266. This includes arguments to builtin commands such as @code{declare} that
  1267. accept assignment statements (@var{declaration} commands).
  1268. When @samp{+=} is applied to a variable for which the @var{integer} attribute
  1269. has been set, @var{value} is evaluated as an arithmetic expression and
  1270. added to the variable's current value, which is also evaluated.
  1271. When @samp{+=} is applied to an array variable using compound assignment
  1272. (@pxref{Arrays}), the
  1273. variable's value is not unset (as it is when using @samp{=}), and new
  1274. values are appended to the array beginning at one greater than the array's
  1275. maximum index (for indexed arrays), or added as additional key-value pairs
  1276. in an associative array.
  1277. When applied to a string-valued variable, @var{value} is expanded and
  1278. appended to the variable's value.
  1279. A variable can be assigned the @var{nameref} attribute using the
  1280. @option{-n} option to the @code{declare} or @code{local} builtin commands
  1281. (@pxref{Bash Builtins})
  1282. to create a @var{nameref}, or a reference to another variable.
  1283. This allows variables to be manipulated indirectly.
  1284. Whenever the nameref variable is referenced, assigned to, unset, or has
  1285. its attributes modified (other than using or changing the nameref
  1286. attribute itself), the
  1287. operation is actually performed on the variable specified by the nameref
  1288. variable's value.
  1289. A nameref is commonly used within shell functions to refer to a variable
  1290. whose name is passed as an argument to the function.
  1291. For instance, if a variable name is passed to a shell function as its first
  1292. argument, running
  1293. @example
  1294. declare -n ref=$1
  1295. @end example
  1296. @noindent
  1297. inside the function creates a nameref variable @var{ref} whose value is
  1298. the variable name passed as the first argument.
  1299. References and assignments to @var{ref}, and changes to its attributes,
  1300. are treated as references, assignments, and attribute modifications
  1301. to the variable whose name was passed as @code{$1}.
  1302. If the control variable in a @code{for} loop has the nameref attribute,
  1303. the list of words can be a list of shell variables, and a name reference
  1304. will be established for each word in the list, in turn, when the loop is
  1305. executed.
  1306. Array variables cannot be given the nameref attribute.
  1307. However, nameref variables can reference array variables and subscripted
  1308. array variables.
  1309. Namerefs can be unset using the @option{-n} option to the @code{unset} builtin
  1310. (@pxref{Bourne Shell Builtins}).
  1311. Otherwise, if @code{unset} is executed with the name of a nameref variable
  1312. as an argument, the variable referenced by the nameref variable will be unset.
  1313. @node Positional Parameters
  1314. @subsection Positional Parameters
  1315. @cindex parameters, positional
  1316. A @var{positional parameter} is a parameter denoted by one or more
  1317. digits, other than the single digit @code{0}. Positional parameters are
  1318. assigned from the shell's arguments when it is invoked,
  1319. and may be reassigned using the @code{set} builtin command.
  1320. Positional parameter @code{N} may be referenced as @code{$@{N@}}, or
  1321. as @code{$N} when @code{N} consists of a single digit.
  1322. Positional parameters may not be assigned to with assignment statements.
  1323. The @code{set} and @code{shift} builtins are used to set and
  1324. unset them (@pxref{Shell Builtin Commands}).
  1325. The positional parameters are
  1326. temporarily replaced when a shell function is executed
  1327. (@pxref{Shell Functions}).
  1328. When a positional parameter consisting of more than a single
  1329. digit is expanded, it must be enclosed in braces.
  1330. @node Special Parameters
  1331. @subsection Special Parameters
  1332. @cindex parameters, special
  1333. The shell treats several parameters specially. These parameters may
  1334. only be referenced; assignment to them is not allowed.
  1335. @vtable @code
  1336. @item *
  1337. @vindex $*
  1338. ($*) Expands to the positional parameters, starting from one.
  1339. When the expansion is not within double quotes, each positional parameter
  1340. expands to a separate word.
  1341. In contexts where it is performed, those words
  1342. are subject to further word splitting and pathname expansion.
  1343. When the expansion occurs within double quotes, it expands to a single word
  1344. with the value of each parameter separated by the first character of the
  1345. @env{IFS} special variable. That is, @code{"$*"} is equivalent
  1346. to @code{"$1@var{c}$2@var{c}@dots{}"}, where @var{c}
  1347. is the first character of the value of the @code{IFS}
  1348. variable.
  1349. If @env{IFS} is unset, the parameters are separated by spaces.
  1350. If @env{IFS} is null, the parameters are joined without intervening
  1351. separators.
  1352. @item @@
  1353. @vindex $@@
  1354. ($@@) Expands to the positional parameters, starting from one. When the
  1355. expansion occurs within double quotes, each parameter expands to a
  1356. separate word. That is, @code{"$@@"} is equivalent to
  1357. @code{"$1" "$2" @dots{}}.
  1358. If the double-quoted expansion occurs within a word, the expansion of
  1359. the first parameter is joined with the beginning part of the original
  1360. word, and the expansion of the last parameter is joined with the last
  1361. part of the original word.
  1362. When there are no positional parameters, @code{"$@@"} and
  1363. @code{$@@}
  1364. expand to nothing (i.e., they are removed).
  1365. @item #
  1366. @vindex $#
  1367. ($#) Expands to the number of positional parameters in decimal.
  1368. @item ?
  1369. @vindex $?
  1370. ($?) Expands to the exit status of the most recently executed foreground
  1371. pipeline.
  1372. @item -
  1373. @vindex $-
  1374. ($-, a hyphen.) Expands to the current option flags as specified upon
  1375. invocation, by the @code{set}
  1376. builtin command, or those set by the shell itself
  1377. (such as the @option{-i} option).
  1378. @item $
  1379. @vindex $$
  1380. ($$) Expands to the process @sc{id} of the shell. In a @code{()} subshell, it
  1381. expands to the process @sc{id} of the invoking shell, not the subshell.
  1382. @item !
  1383. @vindex $!
  1384. ($!) Expands to the process @sc{id} of the job most recently placed into the
  1385. background, whether executed as an asynchronous command or using
  1386. the @code{bg} builtin (@pxref{Job Control Builtins}).
  1387. @item 0
  1388. @vindex $0
  1389. ($0) Expands to the name of the shell or shell script. This is set at
  1390. shell initialization. If Bash is invoked with a file of commands
  1391. (@pxref{Shell Scripts}), @code{$0} is set to the name of that file.
  1392. If Bash is started with the @option{-c} option (@pxref{Invoking Bash}),
  1393. then @code{$0} is set to the first argument after the string to be
  1394. executed, if one is present. Otherwise, it is set
  1395. to the filename used to invoke Bash, as given by argument zero.
  1396. @item _
  1397. @vindex $_
  1398. ($_, an underscore.)
  1399. At shell startup, set to the absolute pathname used to invoke the
  1400. shell or shell script being executed as passed in the environment
  1401. or argument list.
  1402. Subsequently, expands to the last argument to the previous command,
  1403. after expansion.
  1404. Also set to the full pathname used to invoke each command executed
  1405. and placed in the environment exported to that command.
  1406. When checking mail, this parameter holds the name of the mail file.
  1407. @end vtable
  1408. @node Shell Expansions
  1409. @section Shell Expansions
  1410. @cindex expansion
  1411. Expansion is performed on the command line after it has been split into
  1412. @code{token}s. There are seven kinds of expansion performed:
  1413. @itemize @bullet
  1414. @item brace expansion
  1415. @item tilde expansion
  1416. @item parameter and variable expansion
  1417. @item command substitution
  1418. @item arithmetic expansion
  1419. @item word splitting
  1420. @item filename expansion
  1421. @end itemize
  1422. @menu
  1423. * Brace Expansion:: Expansion of expressions within braces.
  1424. * Tilde Expansion:: Expansion of the ~ character.
  1425. * Shell Parameter Expansion:: How Bash expands variables to their values.
  1426. * Command Substitution:: Using the output of a command as an argument.
  1427. * Arithmetic Expansion:: How to use arithmetic in shell expansions.
  1428. * Process Substitution:: A way to write and read to and from a
  1429. command.
  1430. * Word Splitting:: How the results of expansion are split into separate
  1431. arguments.
  1432. * Filename Expansion:: A shorthand for specifying filenames matching patterns.
  1433. * Quote Removal:: How and when quote characters are removed from
  1434. words.
  1435. @end menu
  1436. The order of expansions is:
  1437. brace expansion;
  1438. tilde expansion, parameter and variable expansion, arithmetic expansion,
  1439. and command substitution (done in a left-to-right fashion);
  1440. word splitting;
  1441. and filename expansion.
  1442. On systems that can support it, there is an additional expansion
  1443. available: @var{process substitution}.
  1444. This is performed at the
  1445. same time as tilde, parameter, variable, and arithmetic expansion and
  1446. command substitution.
  1447. After these expansions are performed, quote characters present in the
  1448. original word are removed unless they have been quoted themselves
  1449. (@var{quote removal}).
  1450. Only brace expansion, word splitting, and filename expansion
  1451. can change the number of words of the expansion; other expansions
  1452. expand a single word to a single word.
  1453. The only exceptions to this are the expansions of
  1454. @code{"$@@"} (@pxref{Special Parameters}) and @code{"$@{@var{name}[@@]@}"}
  1455. (@pxref{Arrays}).
  1456. After all expansions, @code{quote removal} (@pxref{Quote Removal})
  1457. is performed.
  1458. @node Brace Expansion
  1459. @subsection Brace Expansion
  1460. @cindex brace expansion
  1461. @cindex expansion, brace
  1462. Brace expansion is a mechanism by which arbitrary strings may be generated.
  1463. This mechanism is similar to
  1464. @var{filename expansion} (@pxref{Filename Expansion}),
  1465. but the filenames generated need not exist.
  1466. Patterns to be brace expanded take the form of an optional @var{preamble},
  1467. followed by either a series of comma-separated strings or a sequence expression
  1468. between a pair of braces,
  1469. followed by an optional @var{postscript}.
  1470. The preamble is prefixed to each string contained within the braces, and
  1471. the postscript is then appended to each resulting string, expanding left
  1472. to right.
  1473. Brace expansions may be nested.
  1474. The results of each expanded string are not sorted; left to right order
  1475. is preserved.
  1476. For example,
  1477. @example
  1478. bash$ echo a@{d,c,b@}e
  1479. ade ace abe
  1480. @end example
  1481. A sequence expression takes the form @code{@{@var{x}..@var{y}[..@var{incr}]@}},
  1482. where @var{x} and @var{y} are either integers or single characters,
  1483. and @var{incr}, an optional increment, is an integer.
  1484. When integers are supplied, the expression expands to each number between
  1485. @var{x} and @var{y}, inclusive.
  1486. Supplied integers may be prefixed with @samp{0} to force each term to have the
  1487. same width.
  1488. When either @var{x} or @var{y} begins with a zero, the shell
  1489. attempts to force all generated terms to contain the same number of digits,
  1490. zero-padding where necessary.
  1491. When characters are supplied, the expression expands to each character
  1492. lexicographically between @var{x} and @var{y}, inclusive,
  1493. using the default C locale.
  1494. Note that both @var{x} and @var{y} must be of the same type.
  1495. When the increment is supplied, it is used as the difference between
  1496. each term. The default increment is 1 or -1 as appropriate.
  1497. Brace expansion is performed before any other expansions,
  1498. and any characters special to other expansions are preserved
  1499. in the result. It is strictly textual. Bash
  1500. does not apply any syntactic interpretation to the context of the
  1501. expansion or the text between the braces.
  1502. To avoid conflicts with parameter expansion, the string @samp{$@{}
  1503. is not considered eligible for brace expansion.
  1504. A correctly-formed brace expansion must contain unquoted opening
  1505. and closing braces, and at least one unquoted comma or a valid
  1506. sequence expression.
  1507. Any incorrectly formed brace expansion is left unchanged.
  1508. A @{ or @samp{,} may be quoted with a backslash to prevent its
  1509. being considered part of a brace expression.
  1510. To avoid conflicts with parameter expansion, the string @samp{$@{}
  1511. is not considered eligible for brace expansion.
  1512. This construct is typically used as shorthand when the common
  1513. prefix of the strings to be generated is longer than in the
  1514. above example:
  1515. @example
  1516. mkdir /usr/local/src/bash/@{old,new,dist,bugs@}
  1517. @end example
  1518. or
  1519. @example
  1520. chown root /usr/@{ucb/@{ex,edit@},lib/@{ex?.?*,how_ex@}@}
  1521. @end example
  1522. @node Tilde Expansion
  1523. @subsection Tilde Expansion
  1524. @cindex tilde expansion
  1525. @cindex expansion, tilde
  1526. If a word begins with an unquoted tilde character (@samp{~}), all of the
  1527. characters up to the first unquoted slash (or all characters,
  1528. if there is no unquoted slash) are considered a @var{tilde-prefix}.
  1529. If none of the characters in the tilde-prefix are quoted, the
  1530. characters in the tilde-prefix following the tilde are treated as a
  1531. possible @var{login name}.
  1532. If this login name is the null string, the tilde is replaced with the
  1533. value of the @env{HOME} shell variable.
  1534. If @env{HOME} is unset, the home directory of the user executing the
  1535. shell is substituted instead.
  1536. Otherwise, the tilde-prefix is replaced with the home directory
  1537. associated with the specified login name.
  1538. If the tilde-prefix is @samp{~+}, the value of
  1539. the shell variable @env{PWD} replaces the tilde-prefix.
  1540. If the tilde-prefix is @samp{~-}, the value of the shell variable
  1541. @env{OLDPWD}, if it is set, is substituted.
  1542. If the characters following the tilde in the tilde-prefix consist of a
  1543. number @var{N}, optionally prefixed by a @samp{+} or a @samp{-},
  1544. the tilde-prefix is replaced with the
  1545. corresponding element from the directory stack, as it would be displayed
  1546. by the @code{dirs} builtin invoked with the characters following tilde
  1547. in the tilde-prefix as an argument (@pxref{The Directory Stack}).
  1548. If the tilde-prefix, sans the tilde, consists of a number without a
  1549. leading @samp{+} or @samp{-}, @samp{+} is assumed.
  1550. If the login name is invalid, or the tilde expansion fails, the word is
  1551. left unchanged.
  1552. Each variable assignment is checked for unquoted tilde-prefixes immediately
  1553. following a @samp{:} or the first @samp{=}.
  1554. In these cases, tilde expansion is also performed.
  1555. Consequently, one may use filenames with tildes in assignments to
  1556. @env{PATH}, @env{MAILPATH}, and @env{CDPATH},
  1557. and the shell assigns the expanded value.
  1558. The following table shows how Bash treats unquoted tilde-prefixes:
  1559. @table @code
  1560. @item ~
  1561. The value of @code{$HOME}
  1562. @item ~/foo
  1563. @file{$HOME/foo}
  1564. @item ~fred/foo
  1565. The subdirectory @code{foo} of the home directory of the user
  1566. @code{fred}
  1567. @item ~+/foo
  1568. @file{$PWD/foo}
  1569. @item ~-/foo
  1570. @file{$@{OLDPWD-'~-'@}/foo}
  1571. @item ~@var{N}
  1572. The string that would be displayed by @samp{dirs +@var{N}}
  1573. @item ~+@var{N}
  1574. The string that would be displayed by @samp{dirs +@var{N}}
  1575. @item ~-@var{N}
  1576. The string that would be displayed by @samp{dirs -@var{N}}
  1577. @end table
  1578. @node Shell Parameter Expansion
  1579. @subsection Shell Parameter Expansion
  1580. @cindex parameter expansion
  1581. @cindex expansion, parameter
  1582. The @samp{$} character introduces parameter expansion,
  1583. command substitution, or arithmetic expansion. The parameter name
  1584. or symbol to be expanded may be enclosed in braces, which
  1585. are optional but serve to protect the variable to be expanded from
  1586. characters immediately following it which could be
  1587. interpreted as part of the name.
  1588. When braces are used, the matching ending brace is the first @samp{@}}
  1589. not escaped by a backslash or within a quoted string, and not within an
  1590. embedded arithmetic expansion, command substitution, or parameter
  1591. expansion.
  1592. The basic form of parameter expansion is $@{@var{parameter}@}.
  1593. The value of @var{parameter} is substituted.
  1594. The @var{parameter} is a shell parameter as described above
  1595. (@pxref{Shell Parameters}) or an array reference (@pxref{Arrays}).
  1596. The braces are required when @var{parameter}
  1597. is a positional parameter with more than one digit,
  1598. or when @var{parameter} is followed by a character that is not to be
  1599. interpreted as part of its name.
  1600. If the first character of @var{parameter} is an exclamation point (!),
  1601. and @var{parameter} is not a @var{nameref},
  1602. it introduces a level of variable indirection.
  1603. Bash uses the value of the variable formed from the rest of
  1604. @var{parameter} as the name of the variable; this variable is then
  1605. expanded and that value is used in the rest of the substitution, rather
  1606. than the value of @var{parameter} itself.
  1607. This is known as @code{indirect expansion}.
  1608. If @var{parameter} is a nameref, this expands to the name of the
  1609. variable referenced by @var{parameter} instead of performing the
  1610. complete indirect expansion.
  1611. The exceptions to this are the expansions of $@{!@var{prefix}*@}
  1612. and $@{!@var{name}[@@]@}
  1613. described below.
  1614. The exclamation point must immediately follow the left brace in order to
  1615. introduce indirection.
  1616. In each of the cases below, @var{word} is subject to tilde expansion,
  1617. parameter expansion, command substitution, and arithmetic expansion.
  1618. When not performing substring expansion, using the form described
  1619. below (e.g., @samp{:-}), Bash tests for a parameter that is unset or null.
  1620. Omitting the colon results in a test only for a parameter that is unset.
  1621. Put another way, if the colon is included,
  1622. the operator tests for both @var{parameter}'s existence and that its value
  1623. is not null; if the colon is omitted, the operator tests only for existence.
  1624. @table @code
  1625. @item $@{@var{parameter}:@minus{}@var{word}@}
  1626. If @var{parameter} is unset or null, the expansion of
  1627. @var{word} is substituted. Otherwise, the value of
  1628. @var{parameter} is substituted.
  1629. @item $@{@var{parameter}:=@var{word}@}
  1630. If @var{parameter}
  1631. is unset or null, the expansion of @var{word}
  1632. is assigned to @var{parameter}.
  1633. The value of @var{parameter} is then substituted.
  1634. Positional parameters and special parameters may not be assigned to
  1635. in this way.
  1636. @item $@{@var{parameter}:?@var{word}@}
  1637. If @var{parameter}
  1638. is null or unset, the expansion of @var{word} (or a message
  1639. to that effect if @var{word}
  1640. is not present) is written to the standard error and the shell, if it
  1641. is not interactive, exits. Otherwise, the value of @var{parameter} is
  1642. substituted.
  1643. @item $@{@var{parameter}:+@var{word}@}
  1644. If @var{parameter}
  1645. is null or unset, nothing is substituted, otherwise the expansion of
  1646. @var{word} is substituted.
  1647. @item $@{@var{parameter}:@var{offset}@}
  1648. @itemx $@{@var{parameter}:@var{offset}:@var{length}@}
  1649. This is referred to as Substring Expansion.
  1650. It expands to up to @var{length} characters of the value of @var{parameter}
  1651. starting at the character specified by @var{offset}.
  1652. If @var{parameter} is @samp{@@}, an indexed array subscripted by
  1653. @samp{@@} or @samp{*}, or an associative array name, the results differ as
  1654. described below.
  1655. If @var{length} is omitted, it expands to the substring of the value of
  1656. @var{parameter} starting at the character specified by @var{offset}
  1657. and extending to the end of the value.
  1658. @var{length} and @var{offset} are arithmetic expressions
  1659. (@pxref{Shell Arithmetic}).
  1660. If @var{offset} evaluates to a number less than zero, the value
  1661. is used as an offset in characters
  1662. from the end of the value of @var{parameter}.
  1663. If @var{length} evaluates to a number less than zero,
  1664. it is interpreted as an offset in characters
  1665. from the end of the value of @var{parameter} rather than
  1666. a number of characters, and the expansion is the characters between
  1667. @var{offset} and that result.
  1668. Note that a negative offset must be separated from the colon by at least
  1669. one space to avoid being confused with the @samp{:-} expansion.
  1670. Here are some examples illustrating substring expansion on parameters and
  1671. subscripted arrays:
  1672. @verbatim
  1673. $ string=01234567890abcdefgh
  1674. $ echo ${string:7}
  1675. 7890abcdefgh
  1676. $ echo ${string:7:0}
  1677. $ echo ${string:7:2}
  1678. 78
  1679. $ echo ${string:7:-2}
  1680. 7890abcdef
  1681. $ echo ${string: -7}
  1682. bcdefgh
  1683. $ echo ${string: -7:0}
  1684. $ echo ${string: -7:2}
  1685. bc
  1686. $ echo ${string: -7:-2}
  1687. bcdef
  1688. $ set -- 01234567890abcdefgh
  1689. $ echo ${1:7}
  1690. 7890abcdefgh
  1691. $ echo ${1:7:0}
  1692. $ echo ${1:7:2}
  1693. 78
  1694. $ echo ${1:7:-2}
  1695. 7890abcdef
  1696. $ echo ${1: -7}
  1697. bcdefgh
  1698. $ echo ${1: -7:0}
  1699. $ echo ${1: -7:2}
  1700. bc
  1701. $ echo ${1: -7:-2}
  1702. bcdef
  1703. $ array[0]=01234567890abcdefgh
  1704. $ echo ${array[0]:7}
  1705. 7890abcdefgh
  1706. $ echo ${array[0]:7:0}
  1707. $ echo ${array[0]:7:2}
  1708. 78
  1709. $ echo ${array[0]:7:-2}
  1710. 7890abcdef
  1711. $ echo ${array[0]: -7}
  1712. bcdefgh
  1713. $ echo ${array[0]: -7:0}
  1714. $ echo ${array[0]: -7:2}
  1715. bc
  1716. $ echo ${array[0]: -7:-2}
  1717. bcdef
  1718. @end verbatim
  1719. If @var{parameter} is @samp{@@}, the result is @var{length} positional
  1720. parameters beginning at @var{offset}.
  1721. A negative @var{offset} is taken relative to one greater than the greatest
  1722. positional parameter, so an offset of -1 evaluates to the last positional
  1723. parameter.
  1724. It is an expansion error if @var{length} evaluates to a number less than zero.
  1725. The following examples illustrate substring expansion using positional
  1726. parameters:
  1727. @verbatim
  1728. $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
  1729. $ echo ${@:7}
  1730. 7 8 9 0 a b c d e f g h
  1731. $ echo ${@:7:0}
  1732. $ echo ${@:7:2}
  1733. 7 8
  1734. $ echo ${@:7:-2}
  1735. bash: -2: substring expression < 0
  1736. $ echo ${@: -7:2}
  1737. b c
  1738. $ echo ${@:0}
  1739. ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
  1740. $ echo ${@:0:2}
  1741. ./bash 1
  1742. $ echo ${@: -7:0}
  1743. @end verbatim
  1744. If @var{parameter} is an indexed array name subscripted
  1745. by @samp{@@} or @samp{*}, the result is the @var{length}
  1746. members of the array beginning with @code{$@{@var{parameter}[@var{offset}]@}}.
  1747. A negative @var{offset} is taken relative to one greater than the maximum
  1748. index of the specified array.
  1749. It is an expansion error if @var{length} evaluates to a number less than zero.
  1750. These examples show how you can use substring expansion with indexed
  1751. arrays:
  1752. @verbatim
  1753. $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
  1754. $ echo ${array[@]:7}
  1755. 7 8 9 0 a b c d e f g h
  1756. $ echo ${array[@]:7:2}
  1757. 7 8
  1758. $ echo ${array[@]: -7:2}
  1759. b c
  1760. $ echo ${array[@]: -7:-2}
  1761. bash: -2: substring expression < 0
  1762. $ echo ${array[@]:0}
  1763. 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
  1764. $ echo ${array[@]:0:2}
  1765. 0 1
  1766. $ echo ${array[@]: -7:0}
  1767. @end verbatim
  1768. Substring expansion applied to an associative array produces undefined
  1769. results.
  1770. Substring indexing is zero-based unless the positional parameters
  1771. are used, in which case the indexing starts at 1 by default.
  1772. If @var{offset} is 0, and the positional parameters are used, @code{$@@} is
  1773. prefixed to the list.
  1774. @item $@{!@var{prefix}*@}
  1775. @itemx $@{!@var{prefix}@@@}
  1776. Expands to the names of variables whose names begin with @var{prefix},
  1777. separated by the first character of the @env{IFS} special variable.
  1778. When @samp{@@} is used and the expansion appears within double quotes, each
  1779. variable name expands to a separate word.
  1780. @item $@{!@var{name}[@@]@}
  1781. @itemx $@{!@var{name}[*]@}
  1782. If @var{name} is an array variable, expands to the list of array indices
  1783. (keys) assigned in @var{name}.
  1784. If @var{name} is not an array, expands to 0 if @var{name} is set and null
  1785. otherwise.
  1786. When @samp{@@} is used and the expansion appears within double quotes, each
  1787. key expands to a separate word.
  1788. @item $@{#@var{parameter}@}
  1789. The length in characters of the expanded value of @var{parameter} is
  1790. substituted.
  1791. If @var{parameter} is @samp{*} or @samp{@@}, the value substituted
  1792. is the number of positional parameters.
  1793. If @var{parameter} is an array name subscripted by @samp{*} or @samp{@@},
  1794. the value substituted is the number of elements in the array.
  1795. If @var{parameter}
  1796. is an indexed array name subscripted by a negative number, that number is
  1797. interpreted as relative to one greater than the maximum index of
  1798. @var{parameter}, so negative indices count back from the end of the
  1799. array, and an index of -1 references the last element.
  1800. @item $@{@var{parameter}#@var{word}@}
  1801. @itemx $@{@var{parameter}##@var{word}@}
  1802. The @var{word}
  1803. is expanded to produce a pattern just as in filename
  1804. expansion (@pxref{Filename Expansion}). If the pattern matches
  1805. the beginning of the expanded value of @var{parameter},
  1806. then the result of the expansion is the expanded value of @var{parameter}
  1807. with the shortest matching pattern (the @samp{#} case) or the
  1808. longest matching pattern (the @samp{##} case) deleted.
  1809. If @var{parameter} is @samp{@@} or @samp{*},
  1810. the pattern removal operation is applied to each positional
  1811. parameter in turn, and the expansion is the resultant list.
  1812. If @var{parameter} is an array variable subscripted with
  1813. @samp{@@} or @samp{*},
  1814. the pattern removal operation is applied to each member of the
  1815. array in turn, and the expansion is the resultant list.
  1816. @item $@{@var{parameter}%@var{word}@}
  1817. @itemx $@{@var{parameter}%%@var{word}@}
  1818. The @var{word} is expanded to produce a pattern just as in
  1819. filename expansion.
  1820. If the pattern matches a trailing portion of the expanded value of
  1821. @var{parameter}, then the result of the expansion is the value of
  1822. @var{parameter} with the shortest matching pattern (the @samp{%} case)
  1823. or the longest matching pattern (the @samp{%%} case) deleted.
  1824. If @var{parameter} is @samp{@@} or @samp{*},
  1825. the pattern removal operation is applied to each positional
  1826. parameter in turn, and the expansion is the resultant list.
  1827. If @var{parameter}
  1828. is an array variable subscripted with @samp{@@} or @samp{*},
  1829. the pattern removal operation is applied to each member of the
  1830. array in turn, and the expansion is the resultant list.
  1831. @item $@{@var{parameter}/@var{pattern}/@var{string}@}
  1832. The @var{pattern} is expanded to produce a pattern just as in
  1833. filename expansion.
  1834. @var{Parameter} is expanded and the longest match of @var{pattern}
  1835. against its value is replaced with @var{string}.
  1836. If @var{pattern} begins with @samp{/}, all matches of @var{pattern} are
  1837. replaced with @var{string}. Normally only the first match is replaced.
  1838. If @var{pattern} begins with @samp{#}, it must match at the beginning
  1839. of the expanded value of @var{parameter}.
  1840. If @var{pattern} begins with @samp{%}, it must match at the end
  1841. of the expanded value of @var{parameter}.
  1842. If @var{string} is null, matches of @var{pattern} are deleted
  1843. and the @code{/} following @var{pattern} may be omitted.
  1844. If the @code{nocasematch} shell option
  1845. (see the description of @code{shopt} in @ref{The Shopt Builtin})
  1846. is enabled, the match is performed without regard to the case
  1847. of alphabetic characters.
  1848. If @var{parameter} is @samp{@@} or @samp{*},
  1849. the substitution operation is applied to each positional
  1850. parameter in turn, and the expansion is the resultant list.
  1851. If @var{parameter}
  1852. is an array variable subscripted with @samp{@@} or @samp{*},
  1853. the substitution operation is applied to each member of the
  1854. array in turn, and the expansion is the resultant list.
  1855. @item $@{@var{parameter}^@var{pattern}@}
  1856. @itemx $@{@var{parameter}^^@var{pattern}@}
  1857. @itemx $@{@var{parameter},@var{pattern}@}
  1858. @itemx $@{@var{parameter},,@var{pattern}@}
  1859. This expansion modifies the case of alphabetic characters in @var{parameter}.
  1860. The @var{pattern} is expanded to produce a pattern just as in
  1861. filename expansion.
  1862. Each character in the expanded value of @var{parameter} is tested against
  1863. @var{pattern}, and, if it matches the pattern, its case is converted.
  1864. The pattern should not attempt to match more than one character.
  1865. The @samp{^} operator converts lowercase letters matching @var{pattern}
  1866. to uppercase; the @samp{,} operator converts matching uppercase letters
  1867. to lowercase.
  1868. The @samp{^^} and @samp{,,} expansions convert each matched character in the
  1869. expanded value; the @samp{^} and @samp{,} expansions match and convert only
  1870. the first character in the expanded value.
  1871. If @var{pattern} is omitted, it is treated like a @samp{?}, which matches
  1872. every character.
  1873. If @var{parameter} is @samp{@@} or @samp{*},
  1874. the case modification operation is applied to each positional
  1875. parameter in turn, and the expansion is the resultant list.
  1876. If @var{parameter}
  1877. is an array variable subscripted with @samp{@@} or @samp{*},
  1878. the case modification operation is applied to each member of the
  1879. array in turn, and the expansion is the resultant list.
  1880. @item $@{@var{parameter}@@@var{operator}@}
  1881. The expansion is either a transformation of the value of @var{parameter}
  1882. or information about @var{parameter} itself, depending on the value of
  1883. @var{operator}. Each @var{operator} is a single letter:
  1884. @table @code
  1885. @item Q
  1886. The expansion is a string that is the value of @var{parameter} quoted in a
  1887. format that can be reused as input.
  1888. @item E
  1889. The expansion is a string that is the value of @var{parameter} with backslash
  1890. escape sequences expanded as with the @code{$'@dots{}'} quoting mechansim.
  1891. @item P
  1892. The expansion is a string that is the result of expanding the value of
  1893. @var{parameter} as if it were a prompt string (@pxref{Controlling the Prompt}).
  1894. @item A
  1895. The expansion is a string in the form of
  1896. an assignment statement or @code{declare} command that, if
  1897. evaluated, will recreate @var{parameter} with its attributes and value.
  1898. @item a
  1899. The expansion is a string consisting of flag values representing
  1900. @var{parameter}'s attributes.
  1901. @end table
  1902. If @var{parameter} is @samp{@@} or @samp{*},
  1903. the operation is applied to each positional
  1904. parameter in turn, and the expansion is the resultant list.
  1905. If @var{parameter}
  1906. is an array variable subscripted with @samp{@@} or @samp{*},
  1907. the operation is applied to each member of the
  1908. array in turn, and the expansion is the resultant list.
  1909. The result of the expansion is subject to word splitting and pathname
  1910. expansion as described below.
  1911. @end table
  1912. @node Command Substitution
  1913. @subsection Command Substitution
  1914. @cindex command substitution
  1915. Command substitution allows the output of a command to replace
  1916. the command itself.
  1917. Command substitution occurs when a command is enclosed as follows:
  1918. @example
  1919. $(@var{command})
  1920. @end example
  1921. @noindent
  1922. or
  1923. @example
  1924. `@var{command}`
  1925. @end example
  1926. @noindent
  1927. Bash performs the expansion by executing @var{command} in a subshell environment
  1928. and replacing the command substitution with the standard output of the
  1929. command, with any trailing newlines deleted.
  1930. Embedded newlines are not deleted, but they may be removed during
  1931. word splitting.
  1932. The command substitution @code{$(cat @var{file})} can be
  1933. replaced by the equivalent but faster @code{$(< @var{file})}.
  1934. When the old-style backquote form of substitution is used,
  1935. backslash retains its literal meaning except when followed by
  1936. @samp{$}, @samp{`}, or @samp{\}.
  1937. The first backquote not preceded by a backslash terminates the
  1938. command substitution.
  1939. When using the @code{$(@var{command})} form, all characters between
  1940. the parentheses make up the command; none are treated specially.
  1941. Command substitutions may be nested. To nest when using the backquoted
  1942. form, escape the inner backquotes with backslashes.
  1943. If the substitution appears within double quotes, word splitting and
  1944. filename expansion are not performed on the results.
  1945. @node Arithmetic Expansion
  1946. @subsection Arithmetic Expansion
  1947. @cindex expansion, arithmetic
  1948. @cindex arithmetic expansion
  1949. Arithmetic expansion allows the evaluation of an arithmetic expression
  1950. and the substitution of the result. The format for arithmetic expansion is:
  1951. @example
  1952. $(( @var{expression} ))
  1953. @end example
  1954. The expression is treated as if it were within double quotes, but
  1955. a double quote inside the parentheses is not treated specially.
  1956. All tokens in the expression undergo parameter and variable expansion,
  1957. command substitution, and quote removal.
  1958. The result is treated as the arithmetic expression to be evaluated.
  1959. Arithmetic expansions may be nested.
  1960. The evaluation is performed according to the rules listed below
  1961. (@pxref{Shell Arithmetic}).
  1962. If the expression is invalid, Bash prints a message indicating
  1963. failure to the standard error and no substitution occurs.
  1964. @node Process Substitution
  1965. @subsection Process Substitution
  1966. @cindex process substitution
  1967. Process substitution allows a process's input or output to be
  1968. referred to using a filename.
  1969. It takes the form of
  1970. @example
  1971. <(@var{list})
  1972. @end example
  1973. @noindent
  1974. or
  1975. @example
  1976. >(@var{list})
  1977. @end example
  1978. @noindent
  1979. The process @var{list} is run asynchronously, and its input or output
  1980. appears as a filename.
  1981. This filename is
  1982. passed as an argument to the current command as the result of the
  1983. expansion.
  1984. If the @code{>(@var{list})} form is used, writing to
  1985. the file will provide input for @var{list}. If the
  1986. @code{<(@var{list})} form is used, the file passed as an
  1987. argument should be read to obtain the output of @var{list}.
  1988. Note that no space may appear between the @code{<} or @code{>}
  1989. and the left parenthesis, otherwise the construct would be interpreted
  1990. as a redirection.
  1991. Process substitution is supported on systems that support named
  1992. pipes (@sc{fifo}s) or the @file{/dev/fd} method of naming open files.
  1993. When available, process substitution is performed simultaneously with
  1994. parameter and variable expansion, command substitution, and arithmetic
  1995. expansion.
  1996. @node Word Splitting
  1997. @subsection Word Splitting
  1998. @cindex word splitting
  1999. The shell scans the results of parameter expansion, command substitution,
  2000. and arithmetic expansion that did not occur within double quotes for
  2001. word splitting.
  2002. The shell treats each character of @env{$IFS} as a delimiter, and splits
  2003. the results of the other expansions into words using these characters
  2004. as field terminators.
  2005. If @env{IFS} is unset, or its value is exactly @code{<space><tab><newline>},
  2006. the default, then sequences of
  2007. @code{ <space>}, @code{<tab>}, and @code{<newline>}
  2008. at the beginning and end of the results of the previous
  2009. expansions are ignored, and any sequence of @env{IFS}
  2010. characters not at the beginning or end serves to delimit words.
  2011. If @env{IFS} has a value other than the default, then sequences of
  2012. the whitespace characters @code{space}, @code{tab}, and @code{newline}
  2013. are ignored at the beginning and end of the
  2014. word, as long as the whitespace character is in the
  2015. value of @env{IFS} (an @env{IFS} whitespace character).
  2016. Any character in @env{IFS} that is not @env{IFS}
  2017. whitespace, along with any adjacent @env{IFS}
  2018. whitespace characters, delimits a field. A sequence of @env{IFS}
  2019. whitespace characters is also treated as a delimiter.
  2020. If the value of @env{IFS} is null, no word splitting occurs.
  2021. Explicit null arguments (@code{""} or @code{''}) are retained
  2022. and passed to commands as empty strings.
  2023. Unquoted implicit null arguments, resulting from the expansion of
  2024. parameters that have no values, are removed.
  2025. If a parameter with no value is expanded within double quotes, a
  2026. null argument results and is retained
  2027. and passed to a command as an empty string.
  2028. When a quoted null argument appears as part of a word whose expansion is
  2029. non-null, the null argument is removed.
  2030. That is, the word
  2031. @code{-d''} becomes @code{-d} after word splitting and
  2032. null argument removal.
  2033. Note that if no expansion occurs, no splitting
  2034. is performed.
  2035. @node Filename Expansion
  2036. @subsection Filename Expansion
  2037. @menu
  2038. * Pattern Matching:: How the shell matches patterns.
  2039. @end menu
  2040. @cindex expansion, filename
  2041. @cindex expansion, pathname
  2042. @cindex filename expansion
  2043. @cindex pathname expansion
  2044. After word splitting, unless the @option{-f} option has been set
  2045. (@pxref{The Set Builtin}), Bash scans each word for the characters
  2046. @samp{*}, @samp{?}, and @samp{[}.
  2047. If one of these characters appears, then the word is
  2048. regarded as a @var{pattern},
  2049. and replaced with an alphabetically sorted list of
  2050. filenames matching the pattern (@pxref{Pattern Matching}).
  2051. If no matching filenames are found,
  2052. and the shell option @code{nullglob} is disabled, the word is left
  2053. unchanged.
  2054. If the @code{nullglob} option is set, and no matches are found, the word
  2055. is removed.
  2056. If the @code{failglob} shell option is set, and no matches are found,
  2057. an error message is printed and the command is not executed.
  2058. If the shell option @code{nocaseglob} is enabled, the match is performed
  2059. without regard to the case of alphabetic characters.
  2060. When a pattern is used for filename expansion, the character @samp{.}
  2061. at the start of a filename or immediately following a slash
  2062. must be matched explicitly, unless the shell option @code{dotglob} is set.
  2063. When matching a filename, the slash character must always be
  2064. matched explicitly.
  2065. In other cases, the @samp{.} character is not treated specially.
  2066. See the description of @code{shopt} in @ref{The Shopt Builtin},
  2067. for a description of the @code{nocaseglob}, @code{nullglob},
  2068. @code{failglob}, and @code{dotglob} options.
  2069. The @env{GLOBIGNORE}
  2070. shell variable may be used to restrict the set of filenames matching a
  2071. pattern. If @env{GLOBIGNORE}
  2072. is set, each matching filename that also matches one of the patterns in
  2073. @env{GLOBIGNORE} is removed from the list of matches.
  2074. If the @code{nocaseglob} option is set, the matching against the patterns in
  2075. @env{GLOBIGNORE} is performed without regard to case.
  2076. The filenames
  2077. @file{.} and @file{..}
  2078. are always ignored when @env{GLOBIGNORE}
  2079. is set and not null.
  2080. However, setting @env{GLOBIGNORE} to a non-null value has the effect of
  2081. enabling the @code{dotglob}
  2082. shell option, so all other filenames beginning with a
  2083. @samp{.} will match.
  2084. To get the old behavior of ignoring filenames beginning with a
  2085. @samp{.}, make @samp{.*} one of the patterns in @env{GLOBIGNORE}.
  2086. The @code{dotglob} option is disabled when @env{GLOBIGNORE}
  2087. is unset.
  2088. @node Pattern Matching
  2089. @subsubsection Pattern Matching
  2090. @cindex pattern matching
  2091. @cindex matching, pattern
  2092. Any character that appears in a pattern, other than the special pattern
  2093. characters described below, matches itself.
  2094. The @sc{nul} character may not occur in a pattern.
  2095. A backslash escapes the following character; the
  2096. escaping backslash is discarded when matching.
  2097. The special pattern characters must be quoted if they are to be matched
  2098. literally.
  2099. The special pattern characters have the following meanings:
  2100. @table @code
  2101. @item *
  2102. Matches any string, including the null string.
  2103. When the @code{globstar} shell option is enabled, and @samp{*} is used in
  2104. a filename expansion context, two adjacent @samp{*}s used as a single
  2105. pattern will match all files and zero or more directories and
  2106. subdirectories.
  2107. If followed by a @samp{/}, two adjacent @samp{*}s will match only
  2108. directories and subdirectories.
  2109. @item ?
  2110. Matches any single character.
  2111. @item [@dots{}]
  2112. Matches any one of the enclosed characters. A pair of characters
  2113. separated by a hyphen denotes a @var{range expression};
  2114. any character that falls between those two characters, inclusive,
  2115. using the current locale's collating sequence and character set,
  2116. is matched. If the first character following the
  2117. @samp{[} is a @samp{!} or a @samp{^}
  2118. then any character not enclosed is matched. A @samp{@minus{}}
  2119. may be matched by including it as the first or last character
  2120. in the set. A @samp{]} may be matched by including it as the first
  2121. character in the set.
  2122. The sorting order of characters in range expressions is determined by
  2123. the current locale and the values of the
  2124. @env{LC_COLLATE} and @env{LC_ALL} shell variables, if set.
  2125. For example, in the default C locale, @samp{[a-dx-z]} is equivalent to
  2126. @samp{[abcdxyz]}. Many locales sort characters in dictionary order, and in
  2127. these locales @samp{[a-dx-z]} is typically not equivalent to @samp{[abcdxyz]};
  2128. it might be equivalent to @samp{[aBbCcDdxXyYz]}, for example. To obtain
  2129. the traditional interpretation of ranges in bracket expressions, you can
  2130. force the use of the C locale by setting the @env{LC_COLLATE} or
  2131. @env{LC_ALL} environment variable to the value @samp{C}, or enable the
  2132. @code{globasciiranges} shell option.
  2133. Within @samp{[} and @samp{]}, @var{character classes} can be specified
  2134. using the syntax
  2135. @code{[:}@var{class}@code{:]}, where @var{class} is one of the
  2136. following classes defined in the @sc{posix} standard:
  2137. @example
  2138. alnum alpha ascii blank cntrl digit graph lower
  2139. print punct space upper word xdigit
  2140. @end example
  2141. @noindent
  2142. A character class matches any character belonging to that class.
  2143. The @code{word} character class matches letters, digits, and the character
  2144. @samp{_}.
  2145. Within @samp{[} and @samp{]}, an @var{equivalence class} can be
  2146. specified using the syntax @code{[=}@var{c}@code{=]}, which
  2147. matches all characters with the same collation weight (as defined
  2148. by the current locale) as the character @var{c}.
  2149. Within @samp{[} and @samp{]}, the syntax @code{[.}@var{symbol}@code{.]}
  2150. matches the collating symbol @var{symbol}.
  2151. @end table
  2152. If the @code{extglob} shell option is enabled using the @code{shopt}
  2153. builtin, several extended pattern matching operators are recognized.
  2154. In the following description, a @var{pattern-list} is a list of one
  2155. or more patterns separated by a @samp{|}.
  2156. Composite patterns may be formed using one or more of the following
  2157. sub-patterns:
  2158. @table @code
  2159. @item ?(@var{pattern-list})
  2160. Matches zero or one occurrence of the given patterns.
  2161. @item *(@var{pattern-list})
  2162. Matches zero or more occurrences of the given patterns.
  2163. @item +(@var{pattern-list})
  2164. Matches one or more occurrences of the given patterns.
  2165. @item @@(@var{pattern-list})
  2166. Matches one of the given patterns.
  2167. @item !(@var{pattern-list})
  2168. Matches anything except one of the given patterns.
  2169. @end table
  2170. @node Quote Removal
  2171. @subsection Quote Removal
  2172. After the preceding expansions, all unquoted occurrences of the
  2173. characters @samp{\}, @samp{'}, and @samp{"} that did not
  2174. result from one of the above expansions are removed.
  2175. @node Redirections
  2176. @section Redirections
  2177. @cindex redirection
  2178. Before a command is executed, its input and output
  2179. may be @var{redirected}
  2180. using a special notation interpreted by the shell.
  2181. Redirection allows commands' file handles to be
  2182. duplicated, opened, closed,
  2183. made to refer to different files,
  2184. and can change the files the command reads from and writes to.
  2185. Redirection may also be used to modify file handles in the
  2186. current shell execution environment. The following redirection
  2187. operators may precede or appear anywhere within a
  2188. simple command or may follow a command.
  2189. Redirections are processed in the order they appear, from
  2190. left to right.
  2191. Each redirection that may be preceded by a file descriptor number
  2192. may instead be preceded by a word of the form @{@var{varname}@}.
  2193. In this case, for each redirection operator except
  2194. >&- and <&-, the shell will allocate a file descriptor greater
  2195. than 10 and assign it to @{@var{varname}@}. If >&- or <&- is preceded
  2196. by @{@var{varname}@}, the value of @var{varname} defines the file
  2197. descriptor to close.
  2198. In the following descriptions, if the file descriptor number is
  2199. omitted, and the first character of the redirection operator is
  2200. @samp{<}, the redirection refers to the standard input (file
  2201. descriptor 0). If the first character of the redirection operator
  2202. is @samp{>}, the redirection refers to the standard output (file
  2203. descriptor 1).
  2204. The word following the redirection operator in the following
  2205. descriptions, unless otherwise noted, is subjected to brace expansion,
  2206. tilde expansion, parameter expansion, command substitution, arithmetic
  2207. expansion, quote removal, filename expansion, and word splitting.
  2208. If it expands to more than one word, Bash reports an error.
  2209. Note that the order of redirections is significant. For example,
  2210. the command
  2211. @example
  2212. ls > @var{dirlist} 2>&1
  2213. @end example
  2214. @noindent
  2215. directs both standard output (file descriptor 1) and standard error
  2216. (file descriptor 2) to the file @var{dirlist}, while the command
  2217. @example
  2218. ls 2>&1 > @var{dirlist}
  2219. @end example
  2220. @noindent
  2221. directs only the standard output to file @var{dirlist},
  2222. because the standard error was made a copy of the standard output
  2223. before the standard output was redirected to @var{dirlist}.
  2224. Bash handles several filenames specially when they are used in
  2225. redirections, as described in the following table.
  2226. If the operating system on which Bash is running provides these
  2227. special files, bash will use them; otherwise it will emulate them
  2228. internally with the behavior described below.
  2229. @table @code
  2230. @item /dev/fd/@var{fd}
  2231. If @var{fd} is a valid integer, file descriptor @var{fd} is duplicated.
  2232. @item /dev/stdin
  2233. File descriptor 0 is duplicated.
  2234. @item /dev/stdout
  2235. File descriptor 1 is duplicated.
  2236. @item /dev/stderr
  2237. File descriptor 2 is duplicated.
  2238. @item /dev/tcp/@var{host}/@var{port}
  2239. If @var{host} is a valid hostname or Internet address, and @var{port}
  2240. is an integer port number or service name, Bash attempts to open
  2241. the corresponding TCP socket.
  2242. @item /dev/udp/@var{host}/@var{port}
  2243. If @var{host} is a valid hostname or Internet address, and @var{port}
  2244. is an integer port number or service name, Bash attempts to open
  2245. the corresponding UDP socket.
  2246. @end table
  2247. A failure to open or create a file causes the redirection to fail.
  2248. Redirections using file descriptors greater than 9 should be used with
  2249. care, as they may conflict with file descriptors the shell uses
  2250. internally.
  2251. @subsection Redirecting Input
  2252. Redirection of input causes the file whose name results from
  2253. the expansion of @var{word}
  2254. to be opened for reading on file descriptor @code{n},
  2255. or the standard input (file descriptor 0) if @code{n}
  2256. is not specified.
  2257. The general format for redirecting input is:
  2258. @example
  2259. [@var{n}]<@var{word}
  2260. @end example
  2261. @subsection Redirecting Output
  2262. Redirection of output causes the file whose name results from
  2263. the expansion of @var{word}
  2264. to be opened for writing on file descriptor @var{n},
  2265. or the standard output (file descriptor 1) if @var{n}
  2266. is not specified. If the file does not exist it is created;
  2267. if it does exist it is truncated to zero size.
  2268. The general format for redirecting output is:
  2269. @example
  2270. [@var{n}]>[|]@var{word}
  2271. @end example
  2272. If the redirection operator is @samp{>}, and the @code{noclobber}
  2273. option to the @code{set} builtin has been enabled, the redirection
  2274. will fail if the file whose name results from the expansion of
  2275. @var{word} exists and is a regular file.
  2276. If the redirection operator is @samp{>|}, or the redirection operator is
  2277. @samp{>} and the @code{noclobber} option is not enabled, the redirection
  2278. is attempted even if the file named by @var{word} exists.
  2279. @subsection Appending Redirected Output
  2280. Redirection of output in this fashion
  2281. causes the file whose name results from
  2282. the expansion of @var{word}
  2283. to be opened for appending on file descriptor @var{n},
  2284. or the standard output (file descriptor 1) if @var{n}
  2285. is not specified. If the file does not exist it is created.
  2286. The general format for appending output is:
  2287. @example
  2288. [@var{n}]>>@var{word}
  2289. @end example
  2290. @subsection Redirecting Standard Output and Standard Error
  2291. This construct allows both the
  2292. standard output (file descriptor 1) and
  2293. the standard error output (file descriptor 2)
  2294. to be redirected to the file whose name is the
  2295. expansion of @var{word}.
  2296. There are two formats for redirecting standard output and
  2297. standard error:
  2298. @example
  2299. &>@var{word}
  2300. @end example
  2301. @noindent
  2302. and
  2303. @example
  2304. >&@var{word}
  2305. @end example
  2306. @noindent
  2307. Of the two forms, the first is preferred.
  2308. This is semantically equivalent to
  2309. @example
  2310. >@var{word} 2>&1
  2311. @end example
  2312. When using the second form, @var{word} may not expand to a number or
  2313. @samp{-}. If it does, other redirection operators apply
  2314. (see Duplicating File Descriptors below) for compatibility reasons.
  2315. @subsection Appending Standard Output and Standard Error
  2316. This construct allows both the
  2317. standard output (file descriptor 1) and
  2318. the standard error output (file descriptor 2)
  2319. to be appended to the file whose name is the
  2320. expansion of @var{word}.
  2321. The format for appending standard output and standard error is:
  2322. @example
  2323. &>>@var{word}
  2324. @end example
  2325. @noindent
  2326. This is semantically equivalent to
  2327. @example
  2328. >>@var{word} 2>&1
  2329. @end example
  2330. (see Duplicating File Descriptors below).
  2331. @subsection Here Documents
  2332. This type of redirection instructs the shell to read input from the
  2333. current source until a line containing only @var{word}
  2334. (with no trailing blanks) is seen. All of
  2335. the lines read up to that point are then used as the standard
  2336. input (or file descriptor @var{n} if @var{n} is specified) for a command.
  2337. The format of here-documents is:
  2338. @example
  2339. [@var{n}]<<[@minus{}]@var{word}
  2340. @var{here-document}
  2341. @var{delimiter}
  2342. @end example
  2343. No parameter and variable expansion, command substitution,
  2344. arithmetic expansion, or filename expansion is performed on
  2345. @var{word}. If any part of @var{word} is quoted, the
  2346. @var{delimiter} is the result of quote removal on @var{word},
  2347. and the lines in the here-document are not expanded.
  2348. If @var{word} is unquoted,
  2349. all lines of the here-document are subjected to
  2350. parameter expansion, command substitution, and arithmetic expansion,
  2351. the character sequence @code{\newline} is ignored, and @samp{\}
  2352. must be used to quote the characters
  2353. @samp{\}, @samp{$}, and @samp{`}.
  2354. If the redirection operator is @samp{<<-},
  2355. then all leading tab characters are stripped from input lines and the
  2356. line containing @var{delimiter}.
  2357. This allows here-documents within shell scripts to be indented in a
  2358. natural fashion.
  2359. @subsection Here Strings
  2360. A variant of here documents, the format is:
  2361. @example
  2362. [@var{n}]<<< @var{word}
  2363. @end example
  2364. The @var{word} undergoes
  2365. brace expansion, tilde expansion, parameter and variable expansion,
  2366. command substitution, arithmetic expansion, and quote removal.
  2367. Pathname expansion and word splitting are not performed.
  2368. The result is supplied as a single string,
  2369. with a newline appended,
  2370. to the command on its
  2371. standard input (or file descriptor @var{n} if @var{n} is specified).
  2372. @subsection Duplicating File Descriptors
  2373. The redirection operator
  2374. @example
  2375. [@var{n}]<&@var{word}
  2376. @end example
  2377. @noindent
  2378. is used to duplicate input file descriptors.
  2379. If @var{word}
  2380. expands to one or more digits, the file descriptor denoted by @var{n}
  2381. is made to be a copy of that file descriptor.
  2382. If the digits in @var{word} do not specify a file descriptor open for
  2383. input, a redirection error occurs.
  2384. If @var{word}
  2385. evaluates to @samp{-}, file descriptor @var{n} is closed.
  2386. If @var{n} is not specified, the standard input (file descriptor 0) is used.
  2387. The operator
  2388. @example
  2389. [@var{n}]>&@var{word}
  2390. @end example
  2391. @noindent
  2392. is used similarly to duplicate output file descriptors. If
  2393. @var{n} is not specified, the standard output (file descriptor 1) is used.
  2394. If the digits in @var{word} do not specify a file descriptor open for
  2395. output, a redirection error occurs.
  2396. If @var{word}
  2397. evaluates to @samp{-}, file descriptor @var{n} is closed.
  2398. As a special case, if @var{n} is omitted, and @var{word} does not
  2399. expand to one or more digits or @samp{-}, the standard output and standard
  2400. error are redirected as described previously.
  2401. @subsection Moving File Descriptors
  2402. The redirection operator
  2403. @example
  2404. [@var{n}]<&@var{digit}-
  2405. @end example
  2406. @noindent
  2407. moves the file descriptor @var{digit} to file descriptor @var{n},
  2408. or the standard input (file descriptor 0) if @var{n} is not specified.
  2409. @var{digit} is closed after being duplicated to @var{n}.
  2410. Similarly, the redirection operator
  2411. @example
  2412. [@var{n}]>&@var{digit}-
  2413. @end example
  2414. @noindent
  2415. moves the file descriptor @var{digit} to file descriptor @var{n},
  2416. or the standard output (file descriptor 1) if @var{n} is not specified.
  2417. @subsection Opening File Descriptors for Reading and Writing
  2418. The redirection operator
  2419. @example
  2420. [@var{n}]<>@var{word}
  2421. @end example
  2422. @noindent
  2423. causes the file whose name is the expansion of @var{word}
  2424. to be opened for both reading and writing on file descriptor
  2425. @var{n}, or on file descriptor 0 if @var{n}
  2426. is not specified. If the file does not exist, it is created.
  2427. @node Executing Commands
  2428. @section Executing Commands
  2429. @menu
  2430. * Simple Command Expansion:: How Bash expands simple commands before
  2431. executing them.
  2432. * Command Search and Execution:: How Bash finds commands and runs them.
  2433. * Command Execution Environment:: The environment in which Bash
  2434. executes commands that are not
  2435. shell builtins.
  2436. * Environment:: The environment given to a command.
  2437. * Exit Status:: The status returned by commands and how Bash
  2438. interprets it.
  2439. * Signals:: What happens when Bash or a command it runs
  2440. receives a signal.
  2441. @end menu
  2442. @node Simple Command Expansion
  2443. @subsection Simple Command Expansion
  2444. @cindex command expansion
  2445. When a simple command is executed, the shell performs the following
  2446. expansions, assignments, and redirections, from left to right.
  2447. @enumerate
  2448. @item
  2449. The words that the parser has marked as variable assignments (those
  2450. preceding the command name) and redirections are saved for later
  2451. processing.
  2452. @item
  2453. The words that are not variable assignments or redirections are
  2454. expanded (@pxref{Shell Expansions}).
  2455. If any words remain after expansion, the first word
  2456. is taken to be the name of the command and the remaining words are
  2457. the arguments.
  2458. @item
  2459. Redirections are performed as described above (@pxref{Redirections}).
  2460. @item
  2461. The text after the @samp{=} in each variable assignment undergoes tilde
  2462. expansion, parameter expansion, command substitution, arithmetic expansion,
  2463. and quote removal before being assigned to the variable.
  2464. @end enumerate
  2465. If no command name results, the variable assignments affect the current
  2466. shell environment. Otherwise, the variables are added to the environment
  2467. of the executed command and do not affect the current shell environment.
  2468. If any of the assignments attempts to assign a value to a readonly variable,
  2469. an error occurs, and the command exits with a non-zero status.
  2470. If no command name results, redirections are performed, but do not
  2471. affect the current shell environment. A redirection error causes the
  2472. command to exit with a non-zero status.
  2473. If there is a command name left after expansion, execution proceeds as
  2474. described below. Otherwise, the command exits. If one of the expansions
  2475. contained a command substitution, the exit status of the command is
  2476. the exit status of the last command substitution performed. If there
  2477. were no command substitutions, the command exits with a status of zero.
  2478. @node Command Search and Execution
  2479. @subsection Command Search and Execution
  2480. @cindex command execution
  2481. @cindex command search
  2482. After a command has been split into words, if it results in a
  2483. simple command and an optional list of arguments, the following
  2484. actions are taken.
  2485. @enumerate
  2486. @item
  2487. If the command name contains no slashes, the shell attempts to
  2488. locate it. If there exists a shell function by that name, that
  2489. function is invoked as described in @ref{Shell Functions}.
  2490. @item
  2491. If the name does not match a function, the shell searches for
  2492. it in the list of shell builtins. If a match is found, that
  2493. builtin is invoked.
  2494. @item
  2495. If the name is neither a shell function nor a builtin,
  2496. and contains no slashes, Bash searches each element of
  2497. @env{$PATH} for a directory containing an executable file
  2498. by that name. Bash uses a hash table to remember the full
  2499. pathnames of executable files to avoid multiple @env{PATH} searches
  2500. (see the description of @code{hash} in @ref{Bourne Shell Builtins}).
  2501. A full search of the directories in @env{$PATH}
  2502. is performed only if the command is not found in the hash table.
  2503. If the search is unsuccessful, the shell searches for a defined shell
  2504. function named @code{command_not_found_handle}.
  2505. If that function exists, it is invoked with the original command and
  2506. the original command's arguments as its arguments, and the function's
  2507. exit status becomes the exit status of the shell.
  2508. If that function is not defined, the shell prints an error
  2509. message and returns an exit status of 127.
  2510. @item
  2511. If the search is successful, or if the command name contains
  2512. one or more slashes, the shell executes the named program in
  2513. a separate execution environment.
  2514. Argument 0 is set to the name given, and the remaining arguments
  2515. to the command are set to the arguments supplied, if any.
  2516. @item
  2517. If this execution fails because the file is not in executable
  2518. format, and the file is not a directory, it is assumed to be a
  2519. @var{shell script} and the shell executes it as described in
  2520. @ref{Shell Scripts}.
  2521. @item
  2522. If the command was not begun asynchronously, the shell waits for
  2523. the command to complete and collects its exit status.
  2524. @end enumerate
  2525. @node Command Execution Environment
  2526. @subsection Command Execution Environment
  2527. @cindex execution environment
  2528. The shell has an @var{execution environment}, which consists of the
  2529. following:
  2530. @itemize @bullet
  2531. @item
  2532. open files inherited by the shell at invocation, as modified by
  2533. redirections supplied to the @code{exec} builtin
  2534. @item
  2535. the current working directory as set by @code{cd}, @code{pushd}, or
  2536. @code{popd}, or inherited by the shell at invocation
  2537. @item
  2538. the file creation mode mask as set by @code{umask} or inherited from
  2539. the shell's parent
  2540. @item
  2541. current traps set by @code{trap}
  2542. @item
  2543. shell parameters that are set by variable assignment or with @code{set}
  2544. or inherited from the shell's parent in the environment
  2545. @item
  2546. shell functions defined during execution or inherited from the shell's
  2547. parent in the environment
  2548. @item
  2549. options enabled at invocation (either by default or with command-line
  2550. arguments) or by @code{set}
  2551. @item
  2552. options enabled by @code{shopt} (@pxref{The Shopt Builtin})
  2553. @item
  2554. shell aliases defined with @code{alias} (@pxref{Aliases})
  2555. @item
  2556. various process @sc{id}s, including those of background jobs
  2557. (@pxref{Lists}), the value of @code{$$}, and the value of
  2558. @env{$PPID}
  2559. @end itemize
  2560. When a simple command other than a builtin or shell function
  2561. is to be executed, it
  2562. is invoked in a separate execution environment that consists of
  2563. the following. Unless otherwise noted, the values are inherited
  2564. from the shell.
  2565. @itemize @bullet
  2566. @item
  2567. the shell's open files, plus any modifications and additions specified
  2568. by redirections to the command
  2569. @item
  2570. the current working directory
  2571. @item
  2572. the file creation mode mask
  2573. @item
  2574. shell variables and functions marked for export, along with variables
  2575. exported for the command, passed in the environment (@pxref{Environment})
  2576. @item
  2577. traps caught by the shell are reset to the values inherited from the
  2578. shell's parent, and traps ignored by the shell are ignored
  2579. @end itemize
  2580. A command invoked in this separate environment cannot affect the
  2581. shell's execution environment.
  2582. Command substitution, commands grouped with parentheses,
  2583. and asynchronous commands are invoked in a
  2584. subshell environment that is a duplicate of the shell environment,
  2585. except that traps caught by the shell are reset to the values
  2586. that the shell inherited from its parent at invocation. Builtin
  2587. commands that are invoked as part of a pipeline are also executed
  2588. in a subshell environment. Changes made to the subshell environment
  2589. cannot affect the shell's execution environment.
  2590. Subshells spawned to execute command substitutions inherit the value of
  2591. the @option{-e} option from the parent shell. When not in @sc{posix} mode,
  2592. Bash clears the @option{-e} option in such subshells.
  2593. If a command is followed by a @samp{&} and job control is not active, the
  2594. default standard input for the command is the empty file @file{/dev/null}.
  2595. Otherwise, the invoked command inherits the file descriptors of the calling
  2596. shell as modified by redirections.
  2597. @node Environment
  2598. @subsection Environment
  2599. @cindex environment
  2600. When a program is invoked it is given an array of strings
  2601. called the @var{environment}.
  2602. This is a list of name-value pairs, of the form @code{name=value}.
  2603. Bash provides several ways to manipulate the environment.
  2604. On invocation, the shell scans its own environment and
  2605. creates a parameter for each name found, automatically marking
  2606. it for @var{export}
  2607. to child processes. Executed commands inherit the environment.
  2608. The @code{export} and @samp{declare -x}
  2609. commands allow parameters and functions to be added to and
  2610. deleted from the environment. If the value of a parameter
  2611. in the environment is modified, the new value becomes part
  2612. of the environment, replacing the old. The environment
  2613. inherited by any executed command consists of the shell's
  2614. initial environment, whose values may be modified in the shell,
  2615. less any pairs removed by the @code{unset} and @samp{export -n}
  2616. commands, plus any additions via the @code{export} and
  2617. @samp{declare -x} commands.
  2618. The environment for any simple command
  2619. or function may be augmented temporarily by prefixing it with
  2620. parameter assignments, as described in @ref{Shell Parameters}.
  2621. These assignment statements affect only the environment seen
  2622. by that command.
  2623. If the @option{-k} option is set (@pxref{The Set Builtin}), then all
  2624. parameter assignments are placed in the environment for a command,
  2625. not just those that precede the command name.
  2626. When Bash invokes an external command, the variable @samp{$_}
  2627. is set to the full pathname of the command and passed to that
  2628. command in its environment.
  2629. @node Exit Status
  2630. @subsection Exit Status
  2631. @cindex exit status
  2632. The exit status of an executed command is the value returned by the
  2633. @var{waitpid} system call or equivalent function. Exit statuses
  2634. fall between 0 and 255, though, as explained below, the shell may
  2635. use values above 125 specially. Exit statuses from shell builtins and
  2636. compound commands are also limited to this range. Under certain
  2637. circumstances, the shell will use special values to indicate specific
  2638. failure modes.
  2639. For the shell's purposes, a command which exits with a
  2640. zero exit status has succeeded.
  2641. A non-zero exit status indicates failure.
  2642. This seemingly counter-intuitive scheme is used so there
  2643. is one well-defined way to indicate success and a variety of
  2644. ways to indicate various failure modes.
  2645. When a command terminates on a fatal signal whose number is @var{N},
  2646. Bash uses the value 128+@var{N} as the exit status.
  2647. If a command is not found, the child process created to
  2648. execute it returns a status of 127. If a command is found
  2649. but is not executable, the return status is 126.
  2650. If a command fails because of an error during expansion or redirection,
  2651. the exit status is greater than zero.
  2652. The exit status is used by the Bash conditional commands
  2653. (@pxref{Conditional Constructs}) and some of the list
  2654. constructs (@pxref{Lists}).
  2655. All of the Bash builtins return an exit status of zero if they succeed
  2656. and a non-zero status on failure, so they may be used by the
  2657. conditional and list constructs.
  2658. All builtins return an exit status of 2 to indicate incorrect usage,
  2659. generally invalid options or missing arguments.
  2660. @node Signals
  2661. @subsection Signals
  2662. @cindex signal handling
  2663. When Bash is interactive, in the absence of any traps, it ignores
  2664. @code{SIGTERM} (so that @samp{kill 0} does not kill an interactive shell),
  2665. and @code{SIGINT}
  2666. is caught and handled (so that the @code{wait} builtin is interruptible).
  2667. When Bash receives a @code{SIGINT}, it breaks out of any executing loops.
  2668. In all cases, Bash ignores @code{SIGQUIT}.
  2669. If job control is in effect (@pxref{Job Control}), Bash
  2670. ignores @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
  2671. Non-builtin commands started by Bash have signal handlers set to the
  2672. values inherited by the shell from its parent.
  2673. When job control is not in effect, asynchronous commands
  2674. ignore @code{SIGINT} and @code{SIGQUIT} in addition to these inherited
  2675. handlers.
  2676. Commands run as a result of
  2677. command substitution ignore the keyboard-generated job control signals
  2678. @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
  2679. The shell exits by default upon receipt of a @code{SIGHUP}.
  2680. Before exiting, an interactive shell resends the @code{SIGHUP} to
  2681. all jobs, running or stopped.
  2682. Stopped jobs are sent @code{SIGCONT} to ensure that they receive
  2683. the @code{SIGHUP}.
  2684. To prevent the shell from sending the @code{SIGHUP} signal to a
  2685. particular job, it should be removed
  2686. from the jobs table with the @code{disown}
  2687. builtin (@pxref{Job Control Builtins}) or marked
  2688. to not receive @code{SIGHUP} using @code{disown -h}.
  2689. If the @code{huponexit} shell option has been set with @code{shopt}
  2690. (@pxref{The Shopt Builtin}), Bash sends a @code{SIGHUP} to all jobs when
  2691. an interactive login shell exits.
  2692. If Bash is waiting for a command to complete and receives a signal
  2693. for which a trap has been set, the trap will not be executed until
  2694. the command completes.
  2695. When Bash is waiting for an asynchronous
  2696. command via the @code{wait} builtin, the reception of a signal for
  2697. which a trap has been set will cause the @code{wait} builtin to return
  2698. immediately with an exit status greater than 128, immediately after
  2699. which the trap is executed.
  2700. @node Shell Scripts
  2701. @section Shell Scripts
  2702. @cindex shell script
  2703. A shell script is a text file containing shell commands. When such
  2704. a file is used as the first non-option argument when invoking Bash,
  2705. and neither the @option{-c} nor @option{-s} option is supplied
  2706. (@pxref{Invoking Bash}),
  2707. Bash reads and executes commands from the file, then exits. This
  2708. mode of operation creates a non-interactive shell. The shell first
  2709. searches for the file in the current directory, and looks in the
  2710. directories in @env{$PATH} if not found there.
  2711. When Bash runs
  2712. a shell script, it sets the special parameter @code{0} to the name
  2713. of the file, rather than the name of the shell, and the positional
  2714. parameters are set to the remaining arguments, if any are given.
  2715. If no additional arguments are supplied, the positional parameters
  2716. are unset.
  2717. A shell script may be made executable by using the @code{chmod} command
  2718. to turn on the execute bit. When Bash finds such a file while
  2719. searching the @env{$PATH} for a command, it spawns a subshell to
  2720. execute it. In other words, executing
  2721. @example
  2722. filename @var{arguments}
  2723. @end example
  2724. @noindent
  2725. is equivalent to executing
  2726. @example
  2727. bash filename @var{arguments}
  2728. @end example
  2729. @noindent
  2730. if @code{filename} is an executable shell script.
  2731. This subshell reinitializes itself, so that the effect is as if a
  2732. new shell had been invoked to interpret the script, with the
  2733. exception that the locations of commands remembered by the parent
  2734. (see the description of @code{hash} in @ref{Bourne Shell Builtins})
  2735. are retained by the child.
  2736. Most versions of Unix make this a part of the operating system's command
  2737. execution mechanism. If the first line of a script begins with
  2738. the two characters @samp{#!}, the remainder of the line specifies
  2739. an interpreter for the program.
  2740. Thus, you can specify Bash, @code{awk}, Perl, or some other
  2741. interpreter and write the rest of the script file in that language.
  2742. The arguments to the interpreter
  2743. consist of a single optional argument following the interpreter
  2744. name on the first line of the script file, followed by the name of
  2745. the script file, followed by the rest of the arguments. Bash
  2746. will perform this action on operating systems that do not handle it
  2747. themselves. Note that some older versions of Unix limit the interpreter
  2748. name and argument to a maximum of 32 characters.
  2749. Bash scripts often begin with @code{#! /bin/bash} (assuming that
  2750. Bash has been installed in @file{/bin}), since this ensures that
  2751. Bash will be used to interpret the script, even if it is executed
  2752. under another shell.
  2753. @node Shell Builtin Commands
  2754. @chapter Shell Builtin Commands
  2755. @menu
  2756. * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
  2757. Shell.
  2758. * Bash Builtins:: Table of builtins specific to Bash.
  2759. * Modifying Shell Behavior:: Builtins to modify shell attributes and
  2760. optional behavior.
  2761. * Special Builtins:: Builtin commands classified specially by
  2762. POSIX.
  2763. @end menu
  2764. Builtin commands are contained within the shell itself.
  2765. When the name of a builtin command is used as the first word of
  2766. a simple command (@pxref{Simple Commands}), the shell executes
  2767. the command directly, without invoking another program.
  2768. Builtin commands are necessary to implement functionality impossible
  2769. or inconvenient to obtain with separate utilities.
  2770. This section briefly describes the builtins which Bash inherits from
  2771. the Bourne Shell, as well as the builtin commands which are unique
  2772. to or have been extended in Bash.
  2773. Several builtin commands are described in other chapters: builtin
  2774. commands which provide the Bash interface to the job control
  2775. facilities (@pxref{Job Control Builtins}), the directory stack
  2776. (@pxref{Directory Stack Builtins}), the command history
  2777. (@pxref{Bash History Builtins}), and the programmable completion
  2778. facilities (@pxref{Programmable Completion Builtins}).
  2779. Many of the builtins have been extended by @sc{posix} or Bash.
  2780. Unless otherwise noted, each builtin command documented as accepting
  2781. options preceded by @samp{-} accepts @samp{--}
  2782. to signify the end of the options.
  2783. The @code{:}, @code{true}, @code{false}, and @code{test}
  2784. builtins do not accept options and do not treat @samp{--} specially.
  2785. The @code{exit}, @code{logout}, @code{return},
  2786. @code{break}, @code{continue}, @code{let},
  2787. and @code{shift} builtins accept and process arguments beginning
  2788. with @samp{-} without requiring @samp{--}.
  2789. Other builtins that accept arguments but are not specified as accepting
  2790. options interpret arguments beginning with @samp{-} as invalid options and
  2791. require @samp{--} to prevent this interpretation.
  2792. @node Bourne Shell Builtins
  2793. @section Bourne Shell Builtins
  2794. The following shell builtin commands are inherited from the Bourne Shell.
  2795. These commands are implemented as specified by the @sc{posix} standard.
  2796. @table @code
  2797. @item : @r{(a colon)}
  2798. @btindex :
  2799. @example
  2800. : [@var{arguments}]
  2801. @end example
  2802. Do nothing beyond expanding @var{arguments} and performing redirections.
  2803. The return status is zero.
  2804. @item . @r{(a period)}
  2805. @btindex .
  2806. @example
  2807. . @var{filename} [@var{arguments}]
  2808. @end example
  2809. Read and execute commands from the @var{filename} argument in the
  2810. current shell context. If @var{filename} does not contain a slash,
  2811. the @env{PATH} variable is used to find @var{filename}.
  2812. When Bash is not in @sc{posix} mode, the current directory is searched
  2813. if @var{filename} is not found in @env{$PATH}.
  2814. If any @var{arguments} are supplied, they become the positional
  2815. parameters when @var{filename} is executed. Otherwise the positional
  2816. parameters are unchanged.
  2817. If the @option{-T} option is enabled, @code{source} inherits any trap on
  2818. @code{DEBUG}; if it is not, any @code{DEBUG} trap string is saved and
  2819. restored around the call to @code{source}, and @code{source} unsets the
  2820. @code{DEBUG} trap while it executes.
  2821. If @option{-T} is not set, and the sourced file changes
  2822. the @code{DEBUG} trap, the new value is retained when @code{source} completes.
  2823. The return status is the exit status of the last command executed, or
  2824. zero if no commands are executed. If @var{filename} is not found, or
  2825. cannot be read, the return status is non-zero.
  2826. This builtin is equivalent to @code{source}.
  2827. @item break
  2828. @btindex break
  2829. @example
  2830. break [@var{n}]
  2831. @end example
  2832. Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop.
  2833. If @var{n} is supplied, the @var{n}th enclosing loop is exited.
  2834. @var{n} must be greater than or equal to 1.
  2835. The return status is zero unless @var{n} is not greater than or equal to 1.
  2836. @item cd
  2837. @btindex cd
  2838. @example
  2839. cd [-L|[-P [-e]] [-@@] [@var{directory}]
  2840. @end example
  2841. Change the current working directory to @var{directory}.
  2842. If @var{directory} is not supplied, the value of the @env{HOME}
  2843. shell variable is used.
  2844. Any additional arguments following @var{directory} are ignored.
  2845. If the shell variable
  2846. @env{CDPATH} exists, it is used as a search path:
  2847. each directory name in @env{CDPATH} is searched for
  2848. @var{directory}, with alternative directory names in @env{CDPATH}
  2849. separated by a colon (@samp{:}).
  2850. If @var{directory} begins with a slash, @env{CDPATH} is not used.
  2851. The @option{-P} option means to not follow symbolic links: symbolic links
  2852. are resolved while @code{cd} is traversing @var{directory} and before
  2853. processing an instance of @samp{..} in @var{directory}.
  2854. By default, or when the @option{-L} option is supplied, symbolic links
  2855. in @var{directory} are resolved after @code{cd} processes an instance
  2856. of @samp{..} in @var{directory}.
  2857. If @samp{..} appears in @var{directory}, it is processed by removing the
  2858. immediately preceding pathname component, back to a slash or the beginning
  2859. of @var{directory}.
  2860. If the @option{-e} option is supplied with @option{-P}
  2861. and the current working directory cannot be successfully determined
  2862. after a successful directory change, @code{cd} will return an unsuccessful
  2863. status.
  2864. On systems that support it, the @option{-@@} option presents the extended
  2865. attributes associated with a file as a directory.
  2866. If @var{directory} is @samp{-}, it is converted to @env{$OLDPWD}
  2867. before the directory change is attempted.
  2868. If a non-empty directory name from @env{CDPATH} is used, or if
  2869. @samp{-} is the first argument, and the directory change is
  2870. successful, the absolute pathname of the new working directory is
  2871. written to the standard output.
  2872. The return status is zero if the directory is successfully changed,
  2873. non-zero otherwise.
  2874. @item continue
  2875. @btindex continue
  2876. @example
  2877. continue [@var{n}]
  2878. @end example
  2879. Resume the next iteration of an enclosing @code{for}, @code{while},
  2880. @code{until}, or @code{select} loop.
  2881. If @var{n} is supplied, the execution of the @var{n}th enclosing loop
  2882. is resumed.
  2883. @var{n} must be greater than or equal to 1.
  2884. The return status is zero unless @var{n} is not greater than or equal to 1.
  2885. @item eval
  2886. @btindex eval
  2887. @example
  2888. eval [@var{arguments}]
  2889. @end example
  2890. The arguments are concatenated together into a single command, which is
  2891. then read and executed, and its exit status returned as the exit status
  2892. of @code{eval}.
  2893. If there are no arguments or only empty arguments, the return status is
  2894. zero.
  2895. @item exec
  2896. @btindex exec
  2897. @example
  2898. exec [-cl] [-a @var{name}] [@var{command} [@var{arguments}]]
  2899. @end example
  2900. If @var{command}
  2901. is supplied, it replaces the shell without creating a new process.
  2902. If the @option{-l} option is supplied, the shell places a dash at the
  2903. beginning of the zeroth argument passed to @var{command}.
  2904. This is what the @code{login} program does.
  2905. The @option{-c} option causes @var{command} to be executed with an empty
  2906. environment.
  2907. If @option{-a} is supplied, the shell passes @var{name} as the zeroth
  2908. argument to @var{command}.
  2909. If @var{command}
  2910. cannot be executed for some reason, a non-interactive shell exits,
  2911. unless the @code{execfail} shell option
  2912. is enabled. In that case, it returns failure.
  2913. An interactive shell returns failure if the file cannot be executed.
  2914. If no @var{command} is specified, redirections may be used to affect
  2915. the current shell environment. If there are no redirection errors, the
  2916. return status is zero; otherwise the return status is non-zero.
  2917. @item exit
  2918. @btindex exit
  2919. @example
  2920. exit [@var{n}]
  2921. @end example
  2922. Exit the shell, returning a status of @var{n} to the shell's parent.
  2923. If @var{n} is omitted, the exit status is that of the last command executed.
  2924. Any trap on @code{EXIT} is executed before the shell terminates.
  2925. @item export
  2926. @btindex export
  2927. @example
  2928. export [-fn] [-p] [@var{name}[=@var{value}]]
  2929. @end example
  2930. Mark each @var{name} to be passed to child processes
  2931. in the environment. If the @option{-f} option is supplied, the @var{name}s
  2932. refer to shell functions; otherwise the names refer to shell variables.
  2933. The @option{-n} option means to no longer mark each @var{name} for export.
  2934. If no @var{names} are supplied, or if the @option{-p} option is given, a
  2935. list of names of all exported variables is displayed.
  2936. The @option{-p} option displays output in a form that may be reused as input.
  2937. If a variable name is followed by =@var{value}, the value of
  2938. the variable is set to @var{value}.
  2939. The return status is zero unless an invalid option is supplied, one of
  2940. the names is not a valid shell variable name, or @option{-f} is supplied
  2941. with a name that is not a shell function.
  2942. @item getopts
  2943. @btindex getopts
  2944. @example
  2945. getopts @var{optstring} @var{name} [@var{args}]
  2946. @end example
  2947. @code{getopts} is used by shell scripts to parse positional parameters.
  2948. @var{optstring} contains the option characters to be recognized; if a
  2949. character is followed by a colon, the option is expected to have an
  2950. argument, which should be separated from it by whitespace.
  2951. The colon (@samp{:}) and question mark (@samp{?}) may not be
  2952. used as option characters.
  2953. Each time it is invoked, @code{getopts}
  2954. places the next option in the shell variable @var{name}, initializing
  2955. @var{name} if it does not exist,
  2956. and the index of the next argument to be processed into the
  2957. variable @env{OPTIND}.
  2958. @env{OPTIND} is initialized to 1 each time the shell or a shell script
  2959. is invoked.
  2960. When an option requires an argument,
  2961. @code{getopts} places that argument into the variable @env{OPTARG}.
  2962. The shell does not reset @env{OPTIND} automatically; it must be manually
  2963. reset between multiple calls to @code{getopts} within the same shell
  2964. invocation if a new set of parameters is to be used.
  2965. When the end of options is encountered, @code{getopts} exits with a
  2966. return value greater than zero.
  2967. @env{OPTIND} is set to the index of the first non-option argument,
  2968. and @var{name} is set to @samp{?}.
  2969. @code{getopts}
  2970. normally parses the positional parameters, but if more arguments are
  2971. given in @var{args}, @code{getopts} parses those instead.
  2972. @code{getopts} can report errors in two ways. If the first character of
  2973. @var{optstring} is a colon, @var{silent}
  2974. error reporting is used. In normal operation, diagnostic messages
  2975. are printed when invalid options or missing option arguments are
  2976. encountered.
  2977. If the variable @env{OPTERR}
  2978. is set to 0, no error messages will be displayed, even if the first
  2979. character of @code{optstring} is not a colon.
  2980. If an invalid option is seen,
  2981. @code{getopts} places @samp{?} into @var{name} and, if not silent,
  2982. prints an error message and unsets @env{OPTARG}.
  2983. If @code{getopts} is silent, the option character found is placed in
  2984. @env{OPTARG} and no diagnostic message is printed.
  2985. If a required argument is not found, and @code{getopts}
  2986. is not silent, a question mark (@samp{?}) is placed in @var{name},
  2987. @code{OPTARG} is unset, and a diagnostic message is printed.
  2988. If @code{getopts} is silent, then a colon (@samp{:}) is placed in
  2989. @var{name} and @env{OPTARG} is set to the option character found.
  2990. @item hash
  2991. @btindex hash
  2992. @example
  2993. hash [-r] [-p @var{filename}] [-dt] [@var{name}]
  2994. @end example
  2995. Each time @code{hash} is invoked, it remembers the full pathnames of the
  2996. commands specified as @var{name} arguments,
  2997. so they need not be searched for on subsequent invocations.
  2998. The commands are found by searching through the directories listed in
  2999. @env{$PATH}.
  3000. Any previously-remembered pathname is discarded.
  3001. The @option{-p} option inhibits the path search, and @var{filename} is
  3002. used as the location of @var{name}.
  3003. The @option{-r} option causes the shell to forget all remembered locations.
  3004. The @option{-d} option causes the shell to forget the remembered location
  3005. of each @var{name}.
  3006. If the @option{-t} option is supplied, the full pathname to which each
  3007. @var{name} corresponds is printed. If multiple @var{name} arguments are
  3008. supplied with @option{-t} the @var{name} is printed before the hashed
  3009. full pathname.
  3010. The @option{-l} option causes output to be displayed in a format
  3011. that may be reused as input.
  3012. If no arguments are given, or if only @option{-l} is supplied,
  3013. information about remembered commands is printed.
  3014. The return status is zero unless a @var{name} is not found or an invalid
  3015. option is supplied.
  3016. @item pwd
  3017. @btindex pwd
  3018. @example
  3019. pwd [-LP]
  3020. @end example
  3021. Print the absolute pathname of the current working directory.
  3022. If the @option{-P} option is supplied, the pathname printed will not
  3023. contain symbolic links.
  3024. If the @option{-L} option is supplied, the pathname printed may contain
  3025. symbolic links.
  3026. The return status is zero unless an error is encountered while
  3027. determining the name of the current directory or an invalid option
  3028. is supplied.
  3029. @item readonly
  3030. @btindex readonly
  3031. @example
  3032. readonly [-aAf] [-p] [@var{name}[=@var{value}]] @dots{}
  3033. @end example
  3034. Mark each @var{name} as readonly.
  3035. The values of these names may not be changed by subsequent assignment.
  3036. If the @option{-f} option is supplied, each @var{name} refers to a shell
  3037. function.
  3038. The @option{-a} option means each @var{name} refers to an indexed
  3039. array variable; the @option{-A} option means each @var{name} refers
  3040. to an associative array variable.
  3041. If both options are supplied, @option{-A} takes precedence.
  3042. If no @var{name} arguments are given, or if the @option{-p}
  3043. option is supplied, a list of all readonly names is printed.
  3044. The other options may be used to restrict the output to a subset of
  3045. the set of readonly names.
  3046. The @option{-p} option causes output to be displayed in a format that
  3047. may be reused as input.
  3048. If a variable name is followed by =@var{value}, the value of
  3049. the variable is set to @var{value}.
  3050. The return status is zero unless an invalid option is supplied, one of
  3051. the @var{name} arguments is not a valid shell variable or function name,
  3052. or the @option{-f} option is supplied with a name that is not a shell function.
  3053. @item return
  3054. @btindex return
  3055. @example
  3056. return [@var{n}]
  3057. @end example
  3058. Cause a shell function to stop executing and return the value @var{n}
  3059. to its caller.
  3060. If @var{n} is not supplied, the return value is the exit status of the
  3061. last command executed in the function.
  3062. If @code{return} is executed by a trap handler, the last command used to
  3063. determine the status is the last command executed before the trap handler.
  3064. if @code{return} is executed during a @code{DEBUG} trap, the last command
  3065. used to determine the status is the last command executed by the trap
  3066. handler before @code{return} was invoked.
  3067. @code{return} may also be used to terminate execution of a script
  3068. being executed with the @code{.} (@code{source}) builtin,
  3069. returning either @var{n} or
  3070. the exit status of the last command executed within the script as the exit
  3071. status of the script.
  3072. If @var{n} is supplied, the return value is its least significant
  3073. 8 bits.
  3074. Any command associated with the @code{RETURN} trap is executed
  3075. before execution resumes after the function or script.
  3076. The return status is non-zero if @code{return} is supplied a non-numeric
  3077. argument or is used outside a function
  3078. and not during the execution of a script by @code{.} or @code{source}.
  3079. @item shift
  3080. @btindex shift
  3081. @example
  3082. shift [@var{n}]
  3083. @end example
  3084. Shift the positional parameters to the left by @var{n}.
  3085. The positional parameters from @var{n}+1 @dots{} @code{$#} are
  3086. renamed to @code{$1} @dots{} @code{$#}-@var{n}.
  3087. Parameters represented by the numbers @code{$#} to @code{$#}-@var{n}+1
  3088. are unset.
  3089. @var{n} must be a non-negative number less than or equal to @code{$#}.
  3090. If @var{n} is zero or greater than @code{$#}, the positional parameters
  3091. are not changed.
  3092. If @var{n} is not supplied, it is assumed to be 1.
  3093. The return status is zero unless @var{n} is greater than @code{$#} or
  3094. less than zero, non-zero otherwise.
  3095. @item test
  3096. @itemx [
  3097. @btindex test
  3098. @btindex [
  3099. @example
  3100. test @var{expr}
  3101. @end example
  3102. Evaluate a conditional expression @var{expr} and return a status of 0
  3103. (true) or 1 (false).
  3104. Each operator and operand must be a separate argument.
  3105. Expressions are composed of the primaries described below in
  3106. @ref{Bash Conditional Expressions}.
  3107. @code{test} does not accept any options, nor does it accept and ignore
  3108. an argument of @option{--} as signifying the end of options.
  3109. When the @code{[} form is used, the last argument to the command must
  3110. be a @code{]}.
  3111. Expressions may be combined using the following operators, listed in
  3112. decreasing order of precedence.
  3113. The evaluation depends on the number of arguments; see below.
  3114. Operator precedence is used when there are five or more arguments.
  3115. @table @code
  3116. @item ! @var{expr}
  3117. True if @var{expr} is false.
  3118. @item ( @var{expr} )
  3119. Returns the value of @var{expr}.
  3120. This may be used to override the normal precedence of operators.
  3121. @item @var{expr1} -a @var{expr2}
  3122. True if both @var{expr1} and @var{expr2} are true.
  3123. @item @var{expr1} -o @var{expr2}
  3124. True if either @var{expr1} or @var{expr2} is true.
  3125. @end table
  3126. The @code{test} and @code{[} builtins evaluate conditional
  3127. expressions using a set of rules based on the number of arguments.
  3128. @table @asis
  3129. @item 0 arguments
  3130. The expression is false.
  3131. @item 1 argument
  3132. The expression is true if and only if the argument is not null.
  3133. @item 2 arguments
  3134. If the first argument is @samp{!}, the expression is true if and
  3135. only if the second argument is null.
  3136. If the first argument is one of the unary conditional operators
  3137. (@pxref{Bash Conditional Expressions}), the expression
  3138. is true if the unary test is true.
  3139. If the first argument is not a valid unary operator, the expression is
  3140. false.
  3141. @item 3 arguments
  3142. The following conditions are applied in the order listed.
  3143. If the second argument is one of the binary conditional
  3144. operators (@pxref{Bash Conditional Expressions}), the
  3145. result of the expression is the result of the binary test using the
  3146. first and third arguments as operands.
  3147. The @samp{-a} and @samp{-o} operators are considered binary operators
  3148. when there are three arguments.
  3149. If the first argument is @samp{!}, the value is the negation of
  3150. the two-argument test using the second and third arguments.
  3151. If the first argument is exactly @samp{(} and the third argument is
  3152. exactly @samp{)}, the result is the one-argument test of the second
  3153. argument.
  3154. Otherwise, the expression is false.
  3155. @item 4 arguments
  3156. If the first argument is @samp{!}, the result is the negation of
  3157. the three-argument expression composed of the remaining arguments.
  3158. Otherwise, the expression is parsed and evaluated according to
  3159. precedence using the rules listed above.
  3160. @item 5 or more arguments
  3161. The expression is parsed and evaluated according to precedence
  3162. using the rules listed above.
  3163. @end table
  3164. When used with @code{test} or @samp{[}, the @samp{<} and @samp{>}
  3165. operators sort lexicographically using ASCII ordering.
  3166. @item times
  3167. @btindex times
  3168. @example
  3169. times
  3170. @end example
  3171. Print out the user and system times used by the shell and its children.
  3172. The return status is zero.
  3173. @item trap
  3174. @btindex trap
  3175. @example
  3176. trap [-lp] [@var{arg}] [@var{sigspec} @dots{}]
  3177. @end example
  3178. The commands in @var{arg} are to be read and executed when the
  3179. shell receives signal @var{sigspec}. If @var{arg} is absent (and
  3180. there is a single @var{sigspec}) or
  3181. equal to @samp{-}, each specified signal's disposition is reset
  3182. to the value it had when the shell was started.
  3183. If @var{arg} is the null string, then the signal specified by
  3184. each @var{sigspec} is ignored by the shell and commands it invokes.
  3185. If @var{arg} is not present and @option{-p} has been supplied,
  3186. the shell displays the trap commands associated with each @var{sigspec}.
  3187. If no arguments are supplied, or
  3188. only @option{-p} is given, @code{trap} prints the list of commands
  3189. associated with each signal number in a form that may be reused as
  3190. shell input.
  3191. The @option{-l} option causes the shell to print a list of signal names
  3192. and their corresponding numbers.
  3193. Each @var{sigspec} is either a signal name or a signal number.
  3194. Signal names are case insensitive and the @code{SIG} prefix is optional.
  3195. If a @var{sigspec}
  3196. is @code{0} or @code{EXIT}, @var{arg} is executed when the shell exits.
  3197. If a @var{sigspec} is @code{DEBUG}, the command @var{arg} is executed
  3198. before every simple command, @code{for} command, @code{case} command,
  3199. @code{select} command, every arithmetic @code{for} command, and before
  3200. the first command executes in a shell function.
  3201. Refer to the description of the @code{extdebug} option to the
  3202. @code{shopt} builtin (@pxref{The Shopt Builtin}) for details of its
  3203. effect on the @code{DEBUG} trap.
  3204. If a @var{sigspec} is @code{RETURN}, the command @var{arg} is executed
  3205. each time a shell function or a script executed with the @code{.} or
  3206. @code{source} builtins finishes executing.
  3207. If a @var{sigspec} is @code{ERR}, the command @var{arg}
  3208. is executed whenever
  3209. a pipeline (which may consist of a single simple
  3210. command), a list, or a compound command returns a
  3211. non-zero exit status,
  3212. subject to the following conditions.
  3213. The @code{ERR} trap is not executed if the failed command is part of the
  3214. command list immediately following an @code{until} or @code{while} keyword,
  3215. part of the test following the @code{if} or @code{elif} reserved words,
  3216. part of a command executed in a @code{&&} or @code{||} list
  3217. except the command following the final @code{&&} or @code{||},
  3218. any command in a pipeline but the last,
  3219. or if the command's return
  3220. status is being inverted using @code{!}.
  3221. These are the same conditions obeyed by the @code{errexit} (@option{-e})
  3222. option.
  3223. Signals ignored upon entry to the shell cannot be trapped or reset.
  3224. Trapped signals that are not being ignored are reset to their original
  3225. values in a subshell or subshell environment when one is created.
  3226. The return status is zero unless a @var{sigspec} does not specify a
  3227. valid signal.
  3228. @item umask
  3229. @btindex umask
  3230. @example
  3231. umask [-p] [-S] [@var{mode}]
  3232. @end example
  3233. Set the shell process's file creation mask to @var{mode}. If
  3234. @var{mode} begins with a digit, it is interpreted as an octal number;
  3235. if not, it is interpreted as a symbolic mode mask similar
  3236. to that accepted by the @code{chmod} command. If @var{mode} is
  3237. omitted, the current value of the mask is printed. If the @option{-S}
  3238. option is supplied without a @var{mode} argument, the mask is printed
  3239. in a symbolic format.
  3240. If the @option{-p} option is supplied, and @var{mode}
  3241. is omitted, the output is in a form that may be reused as input.
  3242. The return status is zero if the mode is successfully changed or if
  3243. no @var{mode} argument is supplied, and non-zero otherwise.
  3244. Note that when the mode is interpreted as an octal number, each number
  3245. of the umask is subtracted from @code{7}. Thus, a umask of @code{022}
  3246. results in permissions of @code{755}.
  3247. @item unset
  3248. @btindex unset
  3249. @example
  3250. unset [-fnv] [@var{name}]
  3251. @end example
  3252. Remove each variable or function @var{name}.
  3253. If the @option{-v} option is given, each
  3254. @var{name} refers to a shell variable and that variable is removed.
  3255. If the @option{-f} option is given, the @var{name}s refer to shell
  3256. functions, and the function definition is removed.
  3257. If the @option{-n} option is supplied, and @var{name} is a variable with
  3258. the @var{nameref} attribute, @var{name} will be unset rather than the
  3259. variable it references.
  3260. @option{-n} has no effect if the @option{-f} option is supplied.
  3261. If no options are supplied, each @var{name} refers to a variable; if
  3262. there is no variable by that name, any function with that name is
  3263. unset.
  3264. Readonly variables and functions may not be unset.
  3265. The return status is zero unless a @var{name} is readonly.
  3266. @end table
  3267. @node Bash Builtins
  3268. @section Bash Builtin Commands
  3269. This section describes builtin commands which are unique to
  3270. or have been extended in Bash.
  3271. Some of these commands are specified in the @sc{posix} standard.
  3272. @table @code
  3273. @item alias
  3274. @btindex alias
  3275. @example
  3276. alias [-p] [@var{name}[=@var{value}] @dots{}]
  3277. @end example
  3278. Without arguments or with the @option{-p} option, @code{alias} prints
  3279. the list of aliases on the standard output in a form that allows
  3280. them to be reused as input.
  3281. If arguments are supplied, an alias is defined for each @var{name}
  3282. whose @var{value} is given. If no @var{value} is given, the name
  3283. and value of the alias is printed.
  3284. Aliases are described in @ref{Aliases}.
  3285. @item bind
  3286. @btindex bind
  3287. @example
  3288. bind [-m @var{keymap}] [-lpsvPSVX]
  3289. bind [-m @var{keymap}] [-q @var{function}] [-u @var{function}] [-r @var{keyseq}]
  3290. bind [-m @var{keymap}] -f @var{filename}
  3291. bind [-m @var{keymap}] -x @var{keyseq:shell-command}
  3292. bind [-m @var{keymap}] @var{keyseq:function-name}
  3293. bind [-m @var{keymap}] @var{keyseq:readline-command}
  3294. @end example
  3295. Display current Readline (@pxref{Command Line Editing})
  3296. key and function bindings,
  3297. bind a key sequence to a Readline function or macro,
  3298. or set a Readline variable.
  3299. Each non-option argument is a command as it would appear in a
  3300. Readline initialization file (@pxref{Readline Init File}),
  3301. but each binding or command must be passed as a separate argument; e.g.,
  3302. @samp{"\C-x\C-r":re-read-init-file}.
  3303. Options, if supplied, have the following meanings:
  3304. @table @code
  3305. @item -m @var{keymap}
  3306. Use @var{keymap} as the keymap to be affected by
  3307. the subsequent bindings. Acceptable @var{keymap}
  3308. names are
  3309. @code{emacs},
  3310. @code{emacs-standard},
  3311. @code{emacs-meta},
  3312. @code{emacs-ctlx},
  3313. @code{vi},
  3314. @code{vi-move},
  3315. @code{vi-command}, and
  3316. @code{vi-insert}.
  3317. @code{vi} is equivalent to @code{vi-command} (@code{vi-move} is also a
  3318. synonym); @code{emacs} is equivalent to @code{emacs-standard}.
  3319. @item -l
  3320. List the names of all Readline functions.
  3321. @item -p
  3322. Display Readline function names and bindings in such a way that they
  3323. can be used as input or in a Readline initialization file.
  3324. @item -P
  3325. List current Readline function names and bindings.
  3326. @item -v
  3327. Display Readline variable names and values in such a way that they
  3328. can be used as input or in a Readline initialization file.
  3329. @item -V
  3330. List current Readline variable names and values.
  3331. @item -s
  3332. Display Readline key sequences bound to macros and the strings they output
  3333. in such a way that they can be used as input or in a Readline
  3334. initialization file.
  3335. @item -S
  3336. Display Readline key sequences bound to macros and the strings they output.
  3337. @item -f @var{filename}
  3338. Read key bindings from @var{filename}.
  3339. @item -q @var{function}
  3340. Query about which keys invoke the named @var{function}.
  3341. @item -u @var{function}
  3342. Unbind all keys bound to the named @var{function}.
  3343. @item -r @var{keyseq}
  3344. Remove any current binding for @var{keyseq}.
  3345. @item -x @var{keyseq:shell-command}
  3346. Cause @var{shell-command} to be executed whenever @var{keyseq} is
  3347. entered.
  3348. When @var{shell-command} is executed, the shell sets the
  3349. @code{READLINE_LINE} variable to the contents of the Readline line
  3350. buffer and the @code{READLINE_POINT} variable to the current location
  3351. of the insertion point.
  3352. If the executed command changes the value of @code{READLINE_LINE} or
  3353. @code{READLINE_POINT}, those new values will be reflected in the
  3354. editing state.
  3355. @item -X
  3356. List all key sequences bound to shell commands and the associated commands
  3357. in a format that can be reused as input.
  3358. @end table
  3359. @noindent
  3360. The return status is zero unless an invalid option is supplied or an
  3361. error occurs.
  3362. @item builtin
  3363. @btindex builtin
  3364. @example
  3365. builtin [@var{shell-builtin} [@var{args}]]
  3366. @end example
  3367. Run a shell builtin, passing it @var{args}, and return its exit status.
  3368. This is useful when defining a shell function with the same
  3369. name as a shell builtin, retaining the functionality of the builtin within
  3370. the function.
  3371. The return status is non-zero if @var{shell-builtin} is not a shell
  3372. builtin command.
  3373. @item caller
  3374. @btindex caller
  3375. @example
  3376. caller [@var{expr}]
  3377. @end example
  3378. Returns the context of any active subroutine call (a shell function or
  3379. a script executed with the @code{.} or @code{source} builtins).
  3380. Without @var{expr}, @code{caller} displays the line number and source
  3381. filename of the current subroutine call.
  3382. If a non-negative integer is supplied as @var{expr}, @code{caller}
  3383. displays the line number, subroutine name, and source file corresponding
  3384. to that position in the current execution call stack. This extra
  3385. information may be used, for example, to print a stack trace. The
  3386. current frame is frame 0.
  3387. The return value is 0 unless the shell is not executing a subroutine
  3388. call or @var{expr} does not correspond to a valid position in the
  3389. call stack.
  3390. @item command
  3391. @btindex command
  3392. @example
  3393. command [-pVv] @var{command} [@var{arguments} @dots{}]
  3394. @end example
  3395. Runs @var{command} with @var{arguments} ignoring any shell function
  3396. named @var{command}.
  3397. Only shell builtin commands or commands found by searching the
  3398. @env{PATH} are executed.
  3399. If there is a shell function named @code{ls}, running @samp{command ls}
  3400. within the function will execute the external command @code{ls}
  3401. instead of calling the function recursively.
  3402. The @option{-p} option means to use a default value for @env{PATH}
  3403. that is guaranteed to find all of the standard utilities.
  3404. The return status in this case is 127 if @var{command} cannot be
  3405. found or an error occurred, and the exit status of @var{command}
  3406. otherwise.
  3407. If either the @option{-V} or @option{-v} option is supplied, a
  3408. description of @var{command} is printed. The @option{-v} option
  3409. causes a single word indicating the command or file name used to
  3410. invoke @var{command} to be displayed; the @option{-V} option produces
  3411. a more verbose description. In this case, the return status is
  3412. zero if @var{command} is found, and non-zero if not.
  3413. @item declare
  3414. @btindex declare
  3415. @example
  3416. declare [-aAfFgilnrtux] [-p] [@var{name}[=@var{value}] @dots{}]
  3417. @end example
  3418. Declare variables and give them attributes. If no @var{name}s
  3419. are given, then display the values of variables instead.
  3420. The @option{-p} option will display the attributes and values of each
  3421. @var{name}.
  3422. When @option{-p} is used with @var{name} arguments, additional options,
  3423. other than @option{-f} and @option{-F}, are ignored.
  3424. When @option{-p} is supplied without @var{name} arguments, @code{declare}
  3425. will display the attributes and values of all variables having the
  3426. attributes specified by the additional options.
  3427. If no other options are supplied with @option{-p}, @code{declare} will
  3428. display the attributes and values of all shell variables. The @option{-f}
  3429. option will restrict the display to shell functions.
  3430. The @option{-F} option inhibits the display of function definitions;
  3431. only the function name and attributes are printed.
  3432. If the @code{extdebug} shell option is enabled using @code{shopt}
  3433. (@pxref{The Shopt Builtin}), the source file name and line number where
  3434. each @var{name} is defined are displayed as well.
  3435. @option{-F} implies @option{-f}.
  3436. The @option{-g} option forces variables to be created or modified at
  3437. the global scope, even when @code{declare} is executed in a shell function.
  3438. It is ignored in all other cases.
  3439. The following options can be used to restrict output to variables with
  3440. the specified attributes or to give variables attributes:
  3441. @table @code
  3442. @item -a
  3443. Each @var{name} is an indexed array variable (@pxref{Arrays}).
  3444. @item -A
  3445. Each @var{name} is an associative array variable (@pxref{Arrays}).
  3446. @item -f
  3447. Use function names only.
  3448. @item -i
  3449. The variable is to be treated as
  3450. an integer; arithmetic evaluation (@pxref{Shell Arithmetic}) is
  3451. performed when the variable is assigned a value.
  3452. @item -l
  3453. When the variable is assigned a value, all upper-case characters are
  3454. converted to lower-case.
  3455. The upper-case attribute is disabled.
  3456. @item -n
  3457. Give each @var{name} the @var{nameref} attribute, making
  3458. it a name reference to another variable.
  3459. That other variable is defined by the value of @var{name}.
  3460. All references, assignments, and attribute modifications
  3461. to @var{name}, except for those using or changing the
  3462. @option{-n} attribute itself, are performed on the variable referenced by
  3463. @var{name}'s value.
  3464. The nameref attribute cannot be applied to array variables.
  3465. @item -r
  3466. Make @var{name}s readonly. These names cannot then be assigned values
  3467. by subsequent assignment statements or unset.
  3468. @item -t
  3469. Give each @var{name} the @code{trace} attribute.
  3470. Traced functions inherit the @code{DEBUG} and @code{RETURN} traps from
  3471. the calling shell.
  3472. The trace attribute has no special meaning for variables.
  3473. @item -u
  3474. When the variable is assigned a value, all lower-case characters are
  3475. converted to upper-case.
  3476. The lower-case attribute is disabled.
  3477. @item -x
  3478. Mark each @var{name} for export to subsequent commands via
  3479. the environment.
  3480. @end table
  3481. Using @samp{+} instead of @samp{-} turns off the attribute instead,
  3482. with the exceptions that @samp{+a}
  3483. may not be used to destroy an array variable and @samp{+r} will not
  3484. remove the readonly attribute.
  3485. When used in a function, @code{declare} makes each @var{name} local,
  3486. as with the @code{local} command, unless the @option{-g} option is used.
  3487. If a variable name is followed by =@var{value}, the value of the variable
  3488. is set to @var{value}.
  3489. When using @option{-a} or @option{-A} and the compound assignment syntax to
  3490. create array variables, additional attributes do not take effect until
  3491. subsequent assignments.
  3492. The return status is zero unless an invalid option is encountered,
  3493. an attempt is made to define a function using @samp{-f foo=bar},
  3494. an attempt is made to assign a value to a readonly variable,
  3495. an attempt is made to assign a value to an array variable without
  3496. using the compound assignment syntax (@pxref{Arrays}),
  3497. one of the @var{names} is not a valid shell variable name,
  3498. an attempt is made to turn off readonly status for a readonly variable,
  3499. an attempt is made to turn off array status for an array variable,
  3500. or an attempt is made to display a non-existent function with @option{-f}.
  3501. @item echo
  3502. @btindex echo
  3503. @example
  3504. echo [-neE] [@var{arg} @dots{}]
  3505. @end example
  3506. Output the @var{arg}s, separated by spaces, terminated with a
  3507. newline.
  3508. The return status is 0 unless a write error occurs.
  3509. If @option{-n} is specified, the trailing newline is suppressed.
  3510. If the @option{-e} option is given, interpretation of the following
  3511. backslash-escaped characters is enabled.
  3512. The @option{-E} option disables the interpretation of these escape characters,
  3513. even on systems where they are interpreted by default.
  3514. The @code{xpg_echo} shell option may be used to
  3515. dynamically determine whether or not @code{echo} expands these
  3516. escape characters by default.
  3517. @code{echo} does not interpret @option{--} to mean the end of options.
  3518. @code{echo} interprets the following escape sequences:
  3519. @table @code
  3520. @item \a
  3521. alert (bell)
  3522. @item \b
  3523. backspace
  3524. @item \c
  3525. suppress further output
  3526. @item \e
  3527. @itemx \E
  3528. escape
  3529. @item \f
  3530. form feed
  3531. @item \n
  3532. new line
  3533. @item \r
  3534. carriage return
  3535. @item \t
  3536. horizontal tab
  3537. @item \v
  3538. vertical tab
  3539. @item \\
  3540. backslash
  3541. @item \0@var{nnn}
  3542. the eight-bit character whose value is the octal value @var{nnn}
  3543. (zero to three octal digits)
  3544. @item \x@var{HH}
  3545. the eight-bit character whose value is the hexadecimal value @var{HH}
  3546. (one or two hex digits)
  3547. @item \u@var{HHHH}
  3548. the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
  3549. @var{HHHH} (one to four hex digits)
  3550. @item \U@var{HHHHHHHH}
  3551. the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
  3552. @var{HHHHHHHH} (one to eight hex digits)
  3553. @end table
  3554. @item enable
  3555. @btindex enable
  3556. @example
  3557. enable [-a] [-dnps] [-f @var{filename}] [@var{name} @dots{}]
  3558. @end example
  3559. Enable and disable builtin shell commands.
  3560. Disabling a builtin allows a disk command which has the same name
  3561. as a shell builtin to be executed without specifying a full pathname,
  3562. even though the shell normally searches for builtins before disk commands.
  3563. If @option{-n} is used, the @var{name}s become disabled. Otherwise
  3564. @var{name}s are enabled. For example, to use the @code{test} binary
  3565. found via @env{$PATH} instead of the shell builtin version, type
  3566. @samp{enable -n test}.
  3567. If the @option{-p} option is supplied, or no @var{name} arguments appear,
  3568. a list of shell builtins is printed. With no other arguments, the list
  3569. consists of all enabled shell builtins.
  3570. The @option{-a} option means to list
  3571. each builtin with an indication of whether or not it is enabled.
  3572. The @option{-f} option means to load the new builtin command @var{name}
  3573. from shared object @var{filename}, on systems that support dynamic loading.
  3574. The @option{-d} option will delete a builtin loaded with @option{-f}.
  3575. If there are no options, a list of the shell builtins is displayed.
  3576. The @option{-s} option restricts @code{enable} to the @sc{posix} special
  3577. builtins. If @option{-s} is used with @option{-f}, the new builtin becomes
  3578. a special builtin (@pxref{Special Builtins}).
  3579. The return status is zero unless a @var{name} is not a shell builtin
  3580. or there is an error loading a new builtin from a shared object.
  3581. @item help
  3582. @btindex help
  3583. @example
  3584. help [-dms] [@var{pattern}]
  3585. @end example
  3586. Display helpful information about builtin commands.
  3587. If @var{pattern} is specified, @code{help} gives detailed help
  3588. on all commands matching @var{pattern}, otherwise a list of
  3589. the builtins is printed.
  3590. Options, if supplied, have the following meanings:
  3591. @table @code
  3592. @item -d
  3593. Display a short description of each @var{pattern}
  3594. @item -m
  3595. Display the description of each @var{pattern} in a manpage-like format
  3596. @item -s
  3597. Display only a short usage synopsis for each @var{pattern}
  3598. @end table
  3599. The return status is zero unless no command matches @var{pattern}.
  3600. @item let
  3601. @btindex let
  3602. @example
  3603. let @var{expression} [@var{expression} @dots{}]
  3604. @end example
  3605. The @code{let} builtin allows arithmetic to be performed on shell
  3606. variables. Each @var{expression} is evaluated according to the
  3607. rules given below in @ref{Shell Arithmetic}. If the
  3608. last @var{expression} evaluates to 0, @code{let} returns 1;
  3609. otherwise 0 is returned.
  3610. @item local
  3611. @btindex local
  3612. @example
  3613. local [@var{option}] @var{name}[=@var{value}] @dots{}
  3614. @end example
  3615. For each argument, a local variable named @var{name} is created,
  3616. and assigned @var{value}.
  3617. The @var{option} can be any of the options accepted by @code{declare}.
  3618. @code{local} can only be used within a function; it makes the variable
  3619. @var{name} have a visible scope restricted to that function and its
  3620. children.
  3621. If @var{name} is @samp{-}, the set of shell options is made local to the
  3622. function in which @code{local} is invoked: shell options changed using
  3623. the @code{set} builtin inside the function are restored to their original
  3624. values when the function returns.
  3625. The return status is zero unless @code{local} is used outside
  3626. a function, an invalid @var{name} is supplied, or @var{name} is a
  3627. readonly variable.
  3628. @item logout
  3629. @btindex logout
  3630. @example
  3631. logout [@var{n}]
  3632. @end example
  3633. Exit a login shell, returning a status of @var{n} to the shell's
  3634. parent.
  3635. @item mapfile
  3636. @btindex mapfile
  3637. @example
  3638. mapfile [-d @var{delim}] [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}]
  3639. [-C @var{callback}] [-c @var{quantum}] [@var{array}]
  3640. @end example
  3641. Read lines from the standard input into the indexed array variable @var{array},
  3642. or from file descriptor @var{fd}
  3643. if the @option{-u} option is supplied.
  3644. The variable @code{MAPFILE} is the default @var{array}.
  3645. Options, if supplied, have the following meanings:
  3646. @table @code
  3647. @item -d
  3648. The first character of @var{delim} is used to terminate each input line,
  3649. rather than newline.
  3650. @item -n
  3651. Copy at most @var{count} lines. If @var{count} is 0, all lines are copied.
  3652. @item -O
  3653. Begin assigning to @var{array} at index @var{origin}.
  3654. The default index is 0.
  3655. @item -s
  3656. Discard the first @var{count} lines read.
  3657. @item -t
  3658. Remove a trailing @var{delim} (default newline) from each line read.
  3659. @item -u
  3660. Read lines from file descriptor @var{fd} instead of the standard input.
  3661. @item -C
  3662. Evaluate @var{callback} each time @var{quantum}P lines are read.
  3663. The @option{-c} option specifies @var{quantum}.
  3664. @item -c
  3665. Specify the number of lines read between each call to @var{callback}.
  3666. @end table
  3667. If @option{-C} is specified without @option{-c},
  3668. the default quantum is 5000.
  3669. When @var{callback} is evaluated, it is supplied the index of the next
  3670. array element to be assigned and the line to be assigned to that element
  3671. as additional arguments.
  3672. @var{callback} is evaluated after the line is read but before the
  3673. array element is assigned.
  3674. If not supplied with an explicit origin, @code{mapfile} will clear @var{array}
  3675. before assigning to it.
  3676. @code{mapfile} returns successfully unless an invalid option or option
  3677. argument is supplied, @var{array} is invalid or unassignable, or @var{array}
  3678. is not an indexed array.
  3679. @item printf
  3680. @btindex printf
  3681. @example
  3682. printf [-v @var{var}] @var{format} [@var{arguments}]
  3683. @end example
  3684. Write the formatted @var{arguments} to the standard output under the
  3685. control of the @var{format}.
  3686. The @option{-v} option causes the output to be assigned to the variable
  3687. @var{var} rather than being printed to the standard output.
  3688. The @var{format} is a character string which contains three types of objects:
  3689. plain characters, which are simply copied to standard output, character
  3690. escape sequences, which are converted and copied to the standard output, and
  3691. format specifications, each of which causes printing of the next successive
  3692. @var{argument}.
  3693. In addition to the standard @code{printf(1)} formats, @code{printf}
  3694. interprets the following extensions:
  3695. @table @code
  3696. @item %b
  3697. Causes @code{printf} to expand backslash escape sequences in the
  3698. corresponding @var{argument} in the same way as @code{echo -e}
  3699. (@pxref{Bash Builtins}).
  3700. @item %q
  3701. Causes @code{printf} to output the
  3702. corresponding @var{argument} in a format that can be reused as shell input.
  3703. @item %(@var{datefmt})T
  3704. Causes @code{printf} to output the date-time string resulting from using
  3705. @var{datefmt} as a format string for @code{strftime}(3).
  3706. The corresponding @var{argument} is an integer representing the number of
  3707. seconds since the epoch.
  3708. Two special argument values may be used: -1 represents the current
  3709. time, and -2 represents the time the shell was invoked.
  3710. If no argument is specified, conversion behaves as if -1 had been given.
  3711. This is an exception to the usual @code{printf} behavior.
  3712. @end table
  3713. @noindent
  3714. Arguments to non-string format specifiers are treated as C language constants,
  3715. except that a leading plus or minus sign is allowed, and if the leading
  3716. character is a single or double quote, the value is the ASCII value of
  3717. the following character.
  3718. The @var{format} is reused as necessary to consume all of the @var{arguments}.
  3719. If the @var{format} requires more @var{arguments} than are supplied, the
  3720. extra format specifications behave as if a zero value or null string, as
  3721. appropriate, had been supplied. The return value is zero on success,
  3722. non-zero on failure.
  3723. @item read
  3724. @btindex read
  3725. @example
  3726. read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}]
  3727. [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}]
  3728. @end example
  3729. One line is read from the standard input, or from the file descriptor
  3730. @var{fd} supplied as an argument to the @option{-u} option,
  3731. split into words as described above in @ref{Word Splitting},
  3732. and the first word
  3733. is assigned to the first @var{name}, the second word to the second @var{name},
  3734. and so on.
  3735. If there are more words than names,
  3736. the remaining words and their intervening delimiters are assigned
  3737. to the last @var{name}.
  3738. If there are fewer words read from the input stream than names,
  3739. the remaining names are assigned empty values.
  3740. The characters in the value of the @env{IFS} variable
  3741. are used to split the line into words using the same rules the shell
  3742. uses for expansion (described above in @ref{Word Splitting}).
  3743. The backslash character @samp{\} may be used to remove any special
  3744. meaning for the next character read and for line continuation.
  3745. If no names are supplied, the line read is assigned to the
  3746. variable @env{REPLY}.
  3747. The exit status is zero, unless end-of-file is encountered, @code{read}
  3748. times out (in which case the status is greater than 128),
  3749. a variable assignment error (such as assigning to a readonly variable) occurs,
  3750. or an invalid file descriptor is supplied as the argument to @option{-u}.
  3751. Options, if supplied, have the following meanings:
  3752. @table @code
  3753. @item -a @var{aname}
  3754. The words are assigned to sequential indices of the array variable
  3755. @var{aname}, starting at 0.
  3756. All elements are removed from @var{aname} before the assignment.
  3757. Other @var{name} arguments are ignored.
  3758. @item -d @var{delim}
  3759. The first character of @var{delim} is used to terminate the input line,
  3760. rather than newline.
  3761. @item -e
  3762. Readline (@pxref{Command Line Editing}) is used to obtain the line.
  3763. Readline uses the current (or default, if line editing was not previously
  3764. active) editing settings.
  3765. @item -i @var{text}
  3766. If Readline is being used to read the line, @var{text} is placed into
  3767. the editing buffer before editing begins.
  3768. @item -n @var{nchars}
  3769. @code{read} returns after reading @var{nchars} characters rather than
  3770. waiting for a complete line of input, but honors a delimiter if fewer
  3771. than @var{nchars} characters are read before the delimiter.
  3772. @item -N @var{nchars}
  3773. @code{read} returns after reading exactly @var{nchars} characters rather
  3774. than waiting for a complete line of input, unless EOF is encountered or
  3775. @code{read} times out.
  3776. Delimiter characters encountered in the input are
  3777. not treated specially and do not cause @code{read} to return until
  3778. @var{nchars} characters are read.
  3779. The result is not split on the characters in @code{IFS}; the intent is
  3780. that the variable is assigned exactly the characters read
  3781. (with the exception of backslash; see the @option{-r} option below).
  3782. @item -p @var{prompt}
  3783. Display @var{prompt}, without a trailing newline, before attempting
  3784. to read any input.
  3785. The prompt is displayed only if input is coming from a terminal.
  3786. @item -r
  3787. If this option is given, backslash does not act as an escape character.
  3788. The backslash is considered to be part of the line.
  3789. In particular, a backslash-newline pair may not be used as a line
  3790. continuation.
  3791. @item -s
  3792. Silent mode. If input is coming from a terminal, characters are
  3793. not echoed.
  3794. @item -t @var{timeout}
  3795. Cause @code{read} to time out and return failure if a complete line of
  3796. input (or a specified number of characters)
  3797. is not read within @var{timeout} seconds.
  3798. @var{timeout} may be a decimal number with a fractional portion following
  3799. the decimal point.
  3800. This option is only effective if @code{read} is reading input from a
  3801. terminal, pipe, or other special file; it has no effect when reading
  3802. from regular files.
  3803. If @code{read} times out, @code{read} saves any partial input read into
  3804. the specified variable @var{name}.
  3805. If @var{timeout} is 0, @code{read} returns immediately, without trying to
  3806. read and data. The exit status is 0 if input is available on
  3807. the specified file descriptor, non-zero otherwise.
  3808. The exit status is greater than 128 if the timeout is exceeded.
  3809. @item -u @var{fd}
  3810. Read input from file descriptor @var{fd}.
  3811. @end table
  3812. @item readarray
  3813. @btindex readarray
  3814. @example
  3815. readarray [-d @var{delim}] [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}]
  3816. [-C @var{callback}] [-c @var{quantum}] [@var{array}]
  3817. @end example
  3818. Read lines from the standard input into the indexed array variable @var{array},
  3819. or from file descriptor @var{fd}
  3820. if the @option{-u} option is supplied.
  3821. A synonym for @code{mapfile}.
  3822. @item source
  3823. @btindex source
  3824. @example
  3825. source @var{filename}
  3826. @end example
  3827. A synonym for @code{.} (@pxref{Bourne Shell Builtins}).
  3828. @item type
  3829. @btindex type
  3830. @example
  3831. type [-afptP] [@var{name} @dots{}]
  3832. @end example
  3833. For each @var{name}, indicate how it would be interpreted if used as a
  3834. command name.
  3835. If the @option{-t} option is used, @code{type} prints a single word
  3836. which is one of @samp{alias}, @samp{function}, @samp{builtin},
  3837. @samp{file} or @samp{keyword},
  3838. if @var{name} is an alias, shell function, shell builtin,
  3839. disk file, or shell reserved word, respectively.
  3840. If the @var{name} is not found, then nothing is printed, and
  3841. @code{type} returns a failure status.
  3842. If the @option{-p} option is used, @code{type} either returns the name
  3843. of the disk file that would be executed, or nothing if @option{-t}
  3844. would not return @samp{file}.
  3845. The @option{-P} option forces a path search for each @var{name}, even if
  3846. @option{-t} would not return @samp{file}.
  3847. If a command is hashed, @option{-p} and @option{-P} print the hashed value,
  3848. which is not necessarily the file that appears first in @code{$PATH}.
  3849. If the @option{-a} option is used, @code{type} returns all of the places
  3850. that contain an executable named @var{file}.
  3851. This includes aliases and functions, if and only if the @option{-p} option
  3852. is not also used.
  3853. If the @option{-f} option is used, @code{type} does not attempt to find
  3854. shell functions, as with the @code{command} builtin.
  3855. The return status is zero if all of the @var{names} are found, non-zero
  3856. if any are not found.
  3857. @item typeset
  3858. @btindex typeset
  3859. @example
  3860. typeset [-afFgrxilnrtux] [-p] [@var{name}[=@var{value}] @dots{}]
  3861. @end example
  3862. The @code{typeset} command is supplied for compatibility with the Korn
  3863. shell.
  3864. It is a synonym for the @code{declare} builtin command.
  3865. @item ulimit
  3866. @btindex ulimit
  3867. @example
  3868. ulimit [-HSabcdefiklmnpqrstuvxPT] [@var{limit}]
  3869. @end example
  3870. @code{ulimit} provides control over the resources available to processes
  3871. started by the shell, on systems that allow such control. If an
  3872. option is given, it is interpreted as follows:
  3873. @table @code
  3874. @item -S
  3875. Change and report the soft limit associated with a resource.
  3876. @item -H
  3877. Change and report the hard limit associated with a resource.
  3878. @item -a
  3879. All current limits are reported.
  3880. @item -b
  3881. The maximum socket buffer size.
  3882. @item -c
  3883. The maximum size of core files created.
  3884. @item -d
  3885. The maximum size of a process's data segment.
  3886. @item -e
  3887. The maximum scheduling priority ("nice").
  3888. @item -f
  3889. The maximum size of files written by the shell and its children.
  3890. @item -i
  3891. The maximum number of pending signals.
  3892. @item -k
  3893. The maximum number of kqueues that may be allocated.
  3894. @item -l
  3895. The maximum size that may be locked into memory.
  3896. @item -m
  3897. The maximum resident set size (many systems do not honor this limit).
  3898. @item -n
  3899. The maximum number of open file descriptors (most systems do not
  3900. allow this value to be set).
  3901. @item -p
  3902. The pipe buffer size.
  3903. @item -q
  3904. The maximum number of bytes in POSIX message queues.
  3905. @item -r
  3906. The maximum real-time scheduling priority.
  3907. @item -s
  3908. The maximum stack size.
  3909. @item -t
  3910. The maximum amount of cpu time in seconds.
  3911. @item -u
  3912. The maximum number of processes available to a single user.
  3913. @item -v
  3914. The maximum amount of virtual memory available to the shell, and, on
  3915. some systems, to its children.
  3916. @item -x
  3917. The maximum number of file locks.
  3918. @item -P
  3919. The maximum number of pseudoterminals.
  3920. @item -T
  3921. The maximum number of threads.
  3922. @end table
  3923. If @var{limit} is given, and the @option{-a} option is not used,
  3924. @var{limit} is the new value of the specified resource.
  3925. The special @var{limit} values @code{hard}, @code{soft}, and
  3926. @code{unlimited} stand for the current hard limit, the current soft limit,
  3927. and no limit, respectively.
  3928. A hard limit cannot be increased by a non-root user once it is set;
  3929. a soft limit may be increased up to the value of the hard limit.
  3930. Otherwise, the current value of the soft limit for the specified resource
  3931. is printed, unless the @option{-H} option is supplied.
  3932. When setting new limits, if neither @option{-H} nor @option{-S} is supplied,
  3933. both the hard and soft limits are set.
  3934. If no option is given, then @option{-f} is assumed. Values are in 1024-byte
  3935. increments, except for @option{-t}, which is in seconds; @option{-p},
  3936. which is in units of 512-byte blocks;
  3937. @option{-P},
  3938. @option{-T},
  3939. @option{-b},
  3940. @option{-k},
  3941. @option{-n} and @option{-u}, which are unscaled values;
  3942. and, when in @sc{posix} Mode (@pxref{Bash POSIX Mode}),
  3943. @option{-c} and @option{-f}, which are in 512-byte increments.
  3944. The return status is zero unless an invalid option or argument is supplied,
  3945. or an error occurs while setting a new limit.
  3946. @item unalias
  3947. @btindex unalias
  3948. @example
  3949. unalias [-a] [@var{name} @dots{} ]
  3950. @end example
  3951. Remove each @var{name} from the list of aliases. If @option{-a} is
  3952. supplied, all aliases are removed.
  3953. Aliases are described in @ref{Aliases}.
  3954. @end table
  3955. @node Modifying Shell Behavior
  3956. @section Modifying Shell Behavior
  3957. @menu
  3958. * The Set Builtin:: Change the values of shell attributes and
  3959. positional parameters.
  3960. * The Shopt Builtin:: Modify shell optional behavior.
  3961. @end menu
  3962. @node The Set Builtin
  3963. @subsection The Set Builtin
  3964. This builtin is so complicated that it deserves its own section. @code{set}
  3965. allows you to change the values of shell options and set the positional
  3966. parameters, or to display the names and values of shell variables.
  3967. @table @code
  3968. @item set
  3969. @btindex set
  3970. @example
  3971. set [--abefhkmnptuvxBCEHPT] [-o @var{option-name}] [@var{argument} @dots{}]
  3972. set [+abefhkmnptuvxBCEHPT] [+o @var{option-name}] [@var{argument} @dots{}]
  3973. @end example
  3974. If no options or arguments are supplied, @code{set} displays the names
  3975. and values of all shell variables and functions, sorted according to the
  3976. current locale, in a format that may be reused as input
  3977. for setting or resetting the currently-set variables.
  3978. Read-only variables cannot be reset.
  3979. In @sc{posix} mode, only shell variables are listed.
  3980. When options are supplied, they set or unset shell attributes.
  3981. Options, if specified, have the following meanings:
  3982. @table @code
  3983. @item -a
  3984. Each variable or function that is created or modified is given the
  3985. export attribute and marked for export to the environment of
  3986. subsequent commands.
  3987. @item -b
  3988. Cause the status of terminated background jobs to be reported
  3989. immediately, rather than before printing the next primary prompt.
  3990. @item -e
  3991. Exit immediately if
  3992. a pipeline (@pxref{Pipelines}), which may consist of a single simple command
  3993. (@pxref{Simple Commands}),
  3994. a list (@pxref{Lists}),
  3995. or a compound command (@pxref{Compound Commands})
  3996. returns a non-zero status.
  3997. The shell does not exit if the command that fails is part of the
  3998. command list immediately following a @code{while} or @code{until} keyword,
  3999. part of the test in an @code{if} statement,
  4000. part of any command executed in a @code{&&} or @code{||} list except
  4001. the command following the final @code{&&} or @code{||},
  4002. any command in a pipeline but the last,
  4003. or if the command's return status is being inverted with @code{!}.
  4004. If a compound command other than a subshell
  4005. returns a non-zero status because a command failed
  4006. while @option{-e} was being ignored, the shell does not exit.
  4007. A trap on @code{ERR}, if set, is executed before the shell exits.
  4008. This option applies to the shell environment and each subshell environment
  4009. separately (@pxref{Command Execution Environment}), and may cause
  4010. subshells to exit before executing all the commands in the subshell.
  4011. If a compound command or shell function executes in a context where
  4012. @option{-e} is being ignored,
  4013. none of the commands executed within the compound command or function body
  4014. will be affected by the @option{-e} setting, even if @option{-e} is set
  4015. and a command returns a failure status.
  4016. If a compound command or shell function sets @option{-e} while executing in
  4017. a context where @option{-e} is ignored, that setting will not have any
  4018. effect until the compound command or the command containing the function
  4019. call completes.
  4020. @item -f
  4021. Disable filename expansion (globbing).
  4022. @item -h
  4023. Locate and remember (hash) commands as they are looked up for execution.
  4024. This option is enabled by default.
  4025. @item -k
  4026. All arguments in the form of assignment statements are placed
  4027. in the environment for a command, not just those that precede
  4028. the command name.
  4029. @item -m
  4030. Job control is enabled (@pxref{Job Control}).
  4031. All processes run in a separate process group.
  4032. When a background job completes, the shell prints a line
  4033. containing its exit status.
  4034. @item -n
  4035. Read commands but do not execute them.
  4036. This may be used to check a script for syntax errors.
  4037. This option is ignored by interactive shells.
  4038. @item -o @var{option-name}
  4039. Set the option corresponding to @var{option-name}:
  4040. @table @code
  4041. @item allexport
  4042. Same as @code{-a}.
  4043. @item braceexpand
  4044. Same as @code{-B}.
  4045. @item emacs
  4046. Use an @code{emacs}-style line editing interface (@pxref{Command Line Editing}).
  4047. This also affects the editing interface used for @code{read -e}.
  4048. @item errexit
  4049. Same as @code{-e}.
  4050. @item errtrace
  4051. Same as @code{-E}.
  4052. @item functrace
  4053. Same as @code{-T}.
  4054. @item hashall
  4055. Same as @code{-h}.
  4056. @item histexpand
  4057. Same as @code{-H}.
  4058. @item history
  4059. Enable command history, as described in @ref{Bash History Facilities}.
  4060. This option is on by default in interactive shells.
  4061. @item ignoreeof
  4062. An interactive shell will not exit upon reading EOF.
  4063. @item keyword
  4064. Same as @code{-k}.
  4065. @item monitor
  4066. Same as @code{-m}.
  4067. @item noclobber
  4068. Same as @code{-C}.
  4069. @item noexec
  4070. Same as @code{-n}.
  4071. @item noglob
  4072. Same as @code{-f}.
  4073. @item nolog
  4074. Currently ignored.
  4075. @item notify
  4076. Same as @code{-b}.
  4077. @item nounset
  4078. Same as @code{-u}.
  4079. @item onecmd
  4080. Same as @code{-t}.
  4081. @item physical
  4082. Same as @code{-P}.
  4083. @item pipefail
  4084. If set, the return value of a pipeline is the value of the last
  4085. (rightmost) command to exit with a non-zero status, or zero if all
  4086. commands in the pipeline exit successfully.
  4087. This option is disabled by default.
  4088. @item posix
  4089. Change the behavior of Bash where the default operation differs
  4090. from the @sc{posix} standard to match the standard
  4091. (@pxref{Bash POSIX Mode}).
  4092. This is intended to make Bash behave as a strict superset of that
  4093. standard.
  4094. @item privileged
  4095. Same as @code{-p}.
  4096. @item verbose
  4097. Same as @code{-v}.
  4098. @item vi
  4099. Use a @code{vi}-style line editing interface.
  4100. This also affects the editing interface used for @code{read -e}.
  4101. @item xtrace
  4102. Same as @code{-x}.
  4103. @end table
  4104. @item -p
  4105. Turn on privileged mode.
  4106. In this mode, the @env{$BASH_ENV} and @env{$ENV} files are not
  4107. processed, shell functions are not inherited from the environment,
  4108. and the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH} and @env{GLOBIGNORE}
  4109. variables, if they appear in the environment, are ignored.
  4110. If the shell is started with the effective user (group) id not equal to the
  4111. real user (group) id, and the @option{-p} option is not supplied, these actions
  4112. are taken and the effective user id is set to the real user id.
  4113. If the @option{-p} option is supplied at startup, the effective user id is
  4114. not reset.
  4115. Turning this option off causes the effective user
  4116. and group ids to be set to the real user and group ids.
  4117. @item -t
  4118. Exit after reading and executing one command.
  4119. @item -u
  4120. Treat unset variables and parameters other than the special parameters
  4121. @samp{@@} or @samp{*} as an error when performing parameter expansion.
  4122. An error message will be written to the standard error, and a non-interactive
  4123. shell will exit.
  4124. @item -v
  4125. Print shell input lines as they are read.
  4126. @item -x
  4127. Print a trace of simple commands, @code{for} commands, @code{case}
  4128. commands, @code{select} commands, and arithmetic @code{for} commands
  4129. and their arguments or associated word lists after they are
  4130. expanded and before they are executed. The value of the @env{PS4}
  4131. variable is expanded and the resultant value is printed before
  4132. the command and its expanded arguments.
  4133. @item -B
  4134. The shell will perform brace expansion (@pxref{Brace Expansion}).
  4135. This option is on by default.
  4136. @item -C
  4137. Prevent output redirection using @samp{>}, @samp{>&}, and @samp{<>}
  4138. from overwriting existing files.
  4139. @item -E
  4140. If set, any trap on @code{ERR} is inherited by shell functions, command
  4141. substitutions, and commands executed in a subshell environment.
  4142. The @code{ERR} trap is normally not inherited in such cases.
  4143. @item -H
  4144. Enable @samp{!} style history substitution (@pxref{History Interaction}).
  4145. This option is on by default for interactive shells.
  4146. @item -P
  4147. If set, do not resolve symbolic links when performing commands such as
  4148. @code{cd} which change the current directory. The physical directory
  4149. is used instead. By default, Bash follows
  4150. the logical chain of directories when performing commands
  4151. which change the current directory.
  4152. For example, if @file{/usr/sys} is a symbolic link to @file{/usr/local/sys}
  4153. then:
  4154. @example
  4155. $ cd /usr/sys; echo $PWD
  4156. /usr/sys
  4157. $ cd ..; pwd
  4158. /usr
  4159. @end example
  4160. @noindent
  4161. If @code{set -P} is on, then:
  4162. @example
  4163. $ cd /usr/sys; echo $PWD
  4164. /usr/local/sys
  4165. $ cd ..; pwd
  4166. /usr/local
  4167. @end example
  4168. @item -T
  4169. If set, any trap on @code{DEBUG} and @code{RETURN} are inherited by
  4170. shell functions, command substitutions, and commands executed
  4171. in a subshell environment.
  4172. The @code{DEBUG} and @code{RETURN} traps are normally not inherited
  4173. in such cases.
  4174. @item --
  4175. If no arguments follow this option, then the positional parameters are
  4176. unset. Otherwise, the positional parameters are set to the
  4177. @var{arguments}, even if some of them begin with a @samp{-}.
  4178. @item -
  4179. Signal the end of options, cause all remaining @var{arguments}
  4180. to be assigned to the positional parameters. The @option{-x}
  4181. and @option{-v} options are turned off.
  4182. If there are no arguments, the positional parameters remain unchanged.
  4183. @end table
  4184. Using @samp{+} rather than @samp{-} causes these options to be
  4185. turned off. The options can also be used upon invocation of the
  4186. shell. The current set of options may be found in @code{$-}.
  4187. The remaining N @var{arguments} are positional parameters and are
  4188. assigned, in order, to @code{$1}, @code{$2}, @dots{} @code{$N}.
  4189. The special parameter @code{#} is set to N.
  4190. The return status is always zero unless an invalid option is supplied.
  4191. @end table
  4192. @node The Shopt Builtin
  4193. @subsection The Shopt Builtin
  4194. This builtin allows you to change additional shell optional behavior.
  4195. @table @code
  4196. @item shopt
  4197. @btindex shopt
  4198. @example
  4199. shopt [-pqsu] [-o] [@var{optname} @dots{}]
  4200. @end example
  4201. Toggle the values of settings controlling optional shell behavior.
  4202. The settings can be either those listed below, or, if the
  4203. @option{-o} option is used, those available with the @option{-o}
  4204. option to the @code{set} builtin command (@pxref{The Set Builtin}).
  4205. With no options, or with the @option{-p} option, a list of all settable
  4206. options is displayed, with an indication of whether or not each is set.
  4207. The @option{-p} option causes output to be displayed in a form that
  4208. may be reused as input.
  4209. Other options have the following meanings:
  4210. @table @code
  4211. @item -s
  4212. Enable (set) each @var{optname}.
  4213. @item -u
  4214. Disable (unset) each @var{optname}.
  4215. @item -q
  4216. Suppresses normal output; the return status
  4217. indicates whether the @var{optname} is set or unset.
  4218. If multiple @var{optname} arguments are given with @option{-q},
  4219. the return status is zero if all @var{optnames} are enabled;
  4220. non-zero otherwise.
  4221. @item -o
  4222. Restricts the values of
  4223. @var{optname} to be those defined for the @option{-o} option to the
  4224. @code{set} builtin (@pxref{The Set Builtin}).
  4225. @end table
  4226. If either @option{-s} or @option{-u}
  4227. is used with no @var{optname} arguments, @code{shopt} shows only
  4228. those options which are set or unset, respectively.
  4229. Unless otherwise noted, the @code{shopt} options are disabled (off)
  4230. by default.
  4231. The return status when listing options is zero if all @var{optnames}
  4232. are enabled, non-zero otherwise. When setting or unsetting options,
  4233. the return status is zero unless an @var{optname} is not a valid shell
  4234. option.
  4235. The list of @code{shopt} options is:
  4236. @table @code
  4237. @item autocd
  4238. If set, a command name that is the name of a directory is executed as if
  4239. it were the argument to the @code{cd} command.
  4240. This option is only used by interactive shells.
  4241. @item cdable_vars
  4242. If this is set, an argument to the @code{cd} builtin command that
  4243. is not a directory is assumed to be the name of a variable whose
  4244. value is the directory to change to.
  4245. @item cdspell
  4246. If set, minor errors in the spelling of a directory component in a
  4247. @code{cd} command will be corrected.
  4248. The errors checked for are transposed characters,
  4249. a missing character, and a character too many.
  4250. If a correction is found, the corrected path is printed,
  4251. and the command proceeds.
  4252. This option is only used by interactive shells.
  4253. @item checkhash
  4254. If this is set, Bash checks that a command found in the hash
  4255. table exists before trying to execute it. If a hashed command no
  4256. longer exists, a normal path search is performed.
  4257. @item checkjobs
  4258. If set, Bash lists the status of any stopped and running jobs before
  4259. exiting an interactive shell. If any jobs are running, this causes
  4260. the exit to be deferred until a second exit is attempted without an
  4261. intervening command (@pxref{Job Control}).
  4262. The shell always postpones exiting if any jobs are stopped.
  4263. @item checkwinsize
  4264. If set, Bash checks the window size after each command
  4265. and, if necessary, updates the values of
  4266. @env{LINES} and @env{COLUMNS}.
  4267. @item cmdhist
  4268. If set, Bash
  4269. attempts to save all lines of a multiple-line
  4270. command in the same history entry. This allows
  4271. easy re-editing of multi-line commands.
  4272. @item compat31
  4273. If set, Bash
  4274. changes its behavior to that of version 3.1 with respect to quoted
  4275. arguments to the conditional command's @samp{=~} operator
  4276. and with respect to locale-specific
  4277. string comparison when using the @code{[[}
  4278. conditional command's @samp{<} and @samp{>} operators.
  4279. Bash versions prior to bash-4.1 use ASCII collation and strcmp(3);
  4280. bash-4.1 and later use the current locale's collation sequence and strcoll(3).
  4281. @item compat32
  4282. If set, Bash
  4283. changes its behavior to that of version 3.2 with respect to locale-specific
  4284. string comparison when using the @code{[[}
  4285. conditional command's @samp{<} and @samp{>} operators (see previous item)
  4286. and the effect of interrupting a command list.
  4287. Bash versions 3.2 and earlier continue with the next command in the list
  4288. after one terminates due to an interrupt.
  4289. @item compat40
  4290. If set, Bash
  4291. changes its behavior to that of version 4.0 with respect to locale-specific
  4292. string comparison when using the @code{[[}
  4293. conditional command's @samp{<} and @samp{>} operators (see description
  4294. of @code{compat31})
  4295. and the effect of interrupting a command list.
  4296. Bash versions 4.0 and later interrupt the list as if the shell received the
  4297. interrupt; previous versions continue with the next command in the list.
  4298. @item compat41
  4299. If set, Bash, when in @sc{posix} mode, treats a single quote in a double-quoted
  4300. parameter expansion as a special character. The single quotes must match
  4301. (an even number) and the characters between the single quotes are considered
  4302. quoted. This is the behavior of @sc{posix} mode through version 4.1.
  4303. The default Bash behavior remains as in previous versions.
  4304. @item compat42
  4305. If set, Bash
  4306. does not process the replacement string in the pattern substitution word
  4307. expansion using quote removal.
  4308. @item compat43
  4309. If set, Bash
  4310. does not print a warning message if an attempt is made to use a quoted compound
  4311. array assignment as an argument to @code{declare},
  4312. makes word expansion errors
  4313. non-fatal errors that cause the current command to fail (the default behavior is
  4314. to make them fatal errors that cause the shell to exit),
  4315. and does not reset the
  4316. loop state when a shell function is executed (this allows @code{break} or
  4317. @code{continue} in a shell function to affect loops in the caller's context).
  4318. @item complete_fullquote
  4319. If set, Bash
  4320. quotes all shell metacharacters in filenames and directory names when
  4321. performing completion.
  4322. If not set, Bash
  4323. removes metacharacters such as the dollar sign from the set of
  4324. characters that will be quoted in completed filenames
  4325. when these metacharacters appear in shell variable references in words to be
  4326. completed.
  4327. This means that dollar signs in variable names that expand to directories
  4328. will not be quoted;
  4329. however, any dollar signs appearing in filenames will not be quoted, either.
  4330. This is active only when bash is using backslashes to quote completed
  4331. filenames.
  4332. This variable is set by default, which is the default Bash behavior in
  4333. versions through 4.2.
  4334. @item direxpand
  4335. If set, Bash
  4336. replaces directory names with the results of word expansion when performing
  4337. filename completion. This changes the contents of the readline editing
  4338. buffer.
  4339. If not set, Bash attempts to preserve what the user typed.
  4340. @item dirspell
  4341. If set, Bash
  4342. attempts spelling correction on directory names during word completion
  4343. if the directory name initially supplied does not exist.
  4344. @item dotglob
  4345. If set, Bash includes filenames beginning with a `.' in
  4346. the results of filename expansion.
  4347. @item execfail
  4348. If this is set, a non-interactive shell will not exit if
  4349. it cannot execute the file specified as an argument to the @code{exec}
  4350. builtin command. An interactive shell does not exit if @code{exec}
  4351. fails.
  4352. @item expand_aliases
  4353. If set, aliases are expanded as described below under Aliases,
  4354. @ref{Aliases}.
  4355. This option is enabled by default for interactive shells.
  4356. @item extdebug
  4357. If set at shell invocation, arrange to execute the debugger profile
  4358. before the shell starts, identical to the @option{--debugger} option.
  4359. If set after invocation, behavior intended for use by debuggers is enabled:
  4360. @enumerate
  4361. @item
  4362. The @option{-F} option to the @code{declare} builtin (@pxref{Bash Builtins})
  4363. displays the source file name and line number corresponding to each function
  4364. name supplied as an argument.
  4365. @item
  4366. If the command run by the @code{DEBUG} trap returns a non-zero value, the
  4367. next command is skipped and not executed.
  4368. @item
  4369. If the command run by the @code{DEBUG} trap returns a value of 2, and the
  4370. shell is executing in a subroutine (a shell function or a shell script
  4371. executed by the @code{.} or @code{source} builtins), the shell simulates
  4372. a call to @code{return}.
  4373. @item
  4374. @code{BASH_ARGC} and @code{BASH_ARGV} are updated as described in their
  4375. descriptions (@pxref{Bash Variables}).
  4376. @item
  4377. Function tracing is enabled: command substitution, shell functions, and
  4378. subshells invoked with @code{( @var{command} )} inherit the
  4379. @code{DEBUG} and @code{RETURN} traps.
  4380. @item
  4381. Error tracing is enabled: command substitution, shell functions, and
  4382. subshells invoked with @code{( @var{command} )} inherit the
  4383. @code{ERR} trap.
  4384. @end enumerate
  4385. @item extglob
  4386. If set, the extended pattern matching features described above
  4387. (@pxref{Pattern Matching}) are enabled.
  4388. @item extquote
  4389. If set, @code{$'@var{string}'} and @code{$"@var{string}"} quoting is
  4390. performed within @code{$@{@var{parameter}@}} expansions
  4391. enclosed in double quotes. This option is enabled by default.
  4392. @item failglob
  4393. If set, patterns which fail to match filenames during filename expansion
  4394. result in an expansion error.
  4395. @item force_fignore
  4396. If set, the suffixes specified by the @env{FIGNORE} shell variable
  4397. cause words to be ignored when performing word completion even if
  4398. the ignored words are the only possible completions.
  4399. @xref{Bash Variables}, for a description of @env{FIGNORE}.
  4400. This option is enabled by default.
  4401. @item globasciiranges
  4402. If set, range expressions used in pattern matching bracket expressions
  4403. (@pxref{Pattern Matching})
  4404. behave as if in the traditional C locale when performing
  4405. comparisons. That is, the current locale's collating sequence
  4406. is not taken into account, so
  4407. @samp{b} will not collate between @samp{A} and @samp{B},
  4408. and upper-case and lower-case ASCII characters will collate together.
  4409. @item globstar
  4410. If set, the pattern @samp{**} used in a filename expansion context will
  4411. match all files and zero or more directories and subdirectories.
  4412. If the pattern is followed by a @samp{/}, only directories and
  4413. subdirectories match.
  4414. @item gnu_errfmt
  4415. If set, shell error messages are written in the standard @sc{gnu} error
  4416. message format.
  4417. @item histappend
  4418. If set, the history list is appended to the file named by the value
  4419. of the @env{HISTFILE}
  4420. variable when the shell exits, rather than overwriting the file.
  4421. @item histreedit
  4422. If set, and Readline
  4423. is being used, a user is given the opportunity to re-edit a
  4424. failed history substitution.
  4425. @item histverify
  4426. If set, and Readline
  4427. is being used, the results of history substitution are not immediately
  4428. passed to the shell parser. Instead, the resulting line is loaded into
  4429. the Readline editing buffer, allowing further modification.
  4430. @item hostcomplete
  4431. If set, and Readline is being used, Bash will attempt to perform
  4432. hostname completion when a word containing a @samp{@@} is being
  4433. completed (@pxref{Commands For Completion}). This option is enabled
  4434. by default.
  4435. @item huponexit
  4436. If set, Bash will send @code{SIGHUP} to all jobs when an interactive
  4437. login shell exits (@pxref{Signals}).
  4438. @item inherit_errexit
  4439. If set, command substitution inherits the value of the @code{errexit} option,
  4440. instead of unsetting it in the subshell environment.
  4441. This option is enabled when @sc{posix} mode is enabled.
  4442. @item interactive_comments
  4443. Allow a word beginning with @samp{#}
  4444. to cause that word and all remaining characters on that
  4445. line to be ignored in an interactive shell.
  4446. This option is enabled by default.
  4447. @item lastpipe
  4448. If set, and job control is not active, the shell runs the last command of
  4449. a pipeline not executed in the background in the current shell environment.
  4450. @item lithist
  4451. If enabled, and the @code{cmdhist}
  4452. option is enabled, multi-line commands are saved to the history with
  4453. embedded newlines rather than using semicolon separators where possible.
  4454. @item login_shell
  4455. The shell sets this option if it is started as a login shell
  4456. (@pxref{Invoking Bash}).
  4457. The value may not be changed.
  4458. @item mailwarn
  4459. If set, and a file that Bash is checking for mail has been
  4460. accessed since the last time it was checked, the message
  4461. @code{"The mail in @var{mailfile} has been read"} is displayed.
  4462. @item no_empty_cmd_completion
  4463. If set, and Readline is being used, Bash will not attempt to search
  4464. the @env{PATH} for possible completions when completion is attempted
  4465. on an empty line.
  4466. @item nocaseglob
  4467. If set, Bash matches filenames in a case-insensitive fashion when
  4468. performing filename expansion.
  4469. @item nocasematch
  4470. If set, Bash matches patterns in a case-insensitive fashion when
  4471. performing matching while executing @code{case} or @code{[[}
  4472. conditional commands,
  4473. when performing pattern substitution word expansions,
  4474. or when filtering possible completions as part of programmable completion.
  4475. @item nullglob
  4476. If set, Bash allows filename patterns which match no
  4477. files to expand to a null string, rather than themselves.
  4478. @item progcomp
  4479. If set, the programmable completion facilities
  4480. (@pxref{Programmable Completion}) are enabled.
  4481. This option is enabled by default.
  4482. @item promptvars
  4483. If set, prompt strings undergo
  4484. parameter expansion, command substitution, arithmetic
  4485. expansion, and quote removal after being expanded
  4486. as described below (@pxref{Controlling the Prompt}).
  4487. This option is enabled by default.
  4488. @item restricted_shell
  4489. The shell sets this option if it is started in restricted mode
  4490. (@pxref{The Restricted Shell}).
  4491. The value may not be changed.
  4492. This is not reset when the startup files are executed, allowing
  4493. the startup files to discover whether or not a shell is restricted.
  4494. @item shift_verbose
  4495. If this is set, the @code{shift}
  4496. builtin prints an error message when the shift count exceeds the
  4497. number of positional parameters.
  4498. @item sourcepath
  4499. If set, the @code{source} builtin uses the value of @env{PATH}
  4500. to find the directory containing the file supplied as an argument.
  4501. This option is enabled by default.
  4502. @item xpg_echo
  4503. If set, the @code{echo} builtin expands backslash-escape sequences
  4504. by default.
  4505. @end table
  4506. @noindent
  4507. The return status when listing options is zero if all @var{optnames}
  4508. are enabled, non-zero otherwise.
  4509. When setting or unsetting options, the return status is zero unless an
  4510. @var{optname} is not a valid shell option.
  4511. @end table
  4512. @node Special Builtins
  4513. @section Special Builtins
  4514. @cindex special builtin
  4515. For historical reasons, the @sc{posix} standard has classified
  4516. several builtin commands as @emph{special}.
  4517. When Bash is executing in @sc{posix} mode, the special builtins
  4518. differ from other builtin commands in three respects:
  4519. @enumerate
  4520. @item
  4521. Special builtins are found before shell functions during command lookup.
  4522. @item
  4523. If a special builtin returns an error status, a non-interactive shell exits.
  4524. @item
  4525. Assignment statements preceding the command stay in effect in the shell
  4526. environment after the command completes.
  4527. @end enumerate
  4528. When Bash is not executing in @sc{posix} mode, these builtins behave no
  4529. differently than the rest of the Bash builtin commands.
  4530. The Bash @sc{posix} mode is described in @ref{Bash POSIX Mode}.
  4531. These are the @sc{posix} special builtins:
  4532. @example
  4533. @w{break : . continue eval exec exit export readonly return set}
  4534. @w{shift trap unset}
  4535. @end example
  4536. @node Shell Variables
  4537. @chapter Shell Variables
  4538. @menu
  4539. * Bourne Shell Variables:: Variables which Bash uses in the same way
  4540. as the Bourne Shell.
  4541. * Bash Variables:: List of variables that exist in Bash.
  4542. @end menu
  4543. This chapter describes the shell variables that Bash uses.
  4544. Bash automatically assigns default values to a number of variables.
  4545. @node Bourne Shell Variables
  4546. @section Bourne Shell Variables
  4547. Bash uses certain shell variables in the same way as the Bourne shell.
  4548. In some cases, Bash assigns a default value to the variable.
  4549. @vtable @code
  4550. @item CDPATH
  4551. A colon-separated list of directories used as a search path for
  4552. the @code{cd} builtin command.
  4553. @item HOME
  4554. The current user's home directory; the default for the @code{cd} builtin
  4555. command.
  4556. The value of this variable is also used by tilde expansion
  4557. (@pxref{Tilde Expansion}).
  4558. @item IFS
  4559. A list of characters that separate fields; used when the shell splits
  4560. words as part of expansion.
  4561. @item MAIL
  4562. If this parameter is set to a filename or directory name
  4563. and the @env{MAILPATH} variable
  4564. is not set, Bash informs the user of the arrival of mail in
  4565. the specified file or Maildir-format directory.
  4566. @item MAILPATH
  4567. A colon-separated list of filenames which the shell periodically checks
  4568. for new mail.
  4569. Each list entry can specify the message that is printed when new mail
  4570. arrives in the mail file by separating the filename from the message with
  4571. a @samp{?}.
  4572. When used in the text of the message, @code{$_} expands to the name of
  4573. the current mail file.
  4574. @item OPTARG
  4575. The value of the last option argument processed by the @code{getopts} builtin.
  4576. @item OPTIND
  4577. The index of the last option argument processed by the @code{getopts} builtin.
  4578. @item PATH
  4579. A colon-separated list of directories in which the shell looks for
  4580. commands.
  4581. A zero-length (null) directory name in the value of @code{PATH} indicates the
  4582. current directory.
  4583. A null directory name may appear as two adjacent colons, or as an initial
  4584. or trailing colon.
  4585. @item PS1
  4586. The primary prompt string. The default value is @samp{\s-\v\$ }.
  4587. @xref{Controlling the Prompt}, for the complete list of escape
  4588. sequences that are expanded before @env{PS1} is displayed.
  4589. @item PS2
  4590. The secondary prompt string. The default value is @samp{> }.
  4591. @end vtable
  4592. @node Bash Variables
  4593. @section Bash Variables
  4594. These variables are set or used by Bash, but other shells
  4595. do not normally treat them specially.
  4596. A few variables used by Bash are described in different chapters:
  4597. variables for controlling the job control facilities
  4598. (@pxref{Job Control Variables}).
  4599. @vtable @code
  4600. @item BASH
  4601. The full pathname used to execute the current instance of Bash.
  4602. @item BASHOPTS
  4603. A colon-separated list of enabled shell options. Each word in
  4604. the list is a valid argument for the @option{-s} option to the
  4605. @code{shopt} builtin command (@pxref{The Shopt Builtin}).
  4606. The options appearing in @env{BASHOPTS} are those reported
  4607. as @samp{on} by @samp{shopt}.
  4608. If this variable is in the environment when Bash
  4609. starts up, each shell option in the list will be enabled before
  4610. reading any startup files. This variable is readonly.
  4611. @item BASHPID
  4612. Expands to the process ID of the current Bash process.
  4613. This differs from @code{$$} under certain circumstances, such as subshells
  4614. that do not require Bash to be re-initialized.
  4615. @item BASH_ALIASES
  4616. An associative array variable whose members correspond to the internal
  4617. list of aliases as maintained by the @code{alias} builtin.
  4618. (@pxref{Bourne Shell Builtins}).
  4619. Elements added to this array appear in the alias list; however,
  4620. unsetting array elements currently does not cause aliases to be removed
  4621. from the alias list.
  4622. If @code{BASH_ALIASES}
  4623. is unset, it loses its special properties, even if it is
  4624. subsequently reset.
  4625. @item BASH_ARGC
  4626. An array variable whose values are the number of parameters in each
  4627. frame of the current bash execution call stack. The number of
  4628. parameters to the current subroutine (shell function or script executed
  4629. with @code{.} or @code{source}) is at the top of the stack. When a
  4630. subroutine is executed, the number of parameters passed is pushed onto
  4631. @code{BASH_ARGC}.
  4632. The shell sets @code{BASH_ARGC} only when in extended debugging mode
  4633. (see @ref{The Shopt Builtin}
  4634. for a description of the @code{extdebug} option to the @code{shopt}
  4635. builtin).
  4636. @item BASH_ARGV
  4637. An array variable containing all of the parameters in the current bash
  4638. execution call stack. The final parameter of the last subroutine call
  4639. is at the top of the stack; the first parameter of the initial call is
  4640. at the bottom. When a subroutine is executed, the parameters supplied
  4641. are pushed onto @code{BASH_ARGV}.
  4642. The shell sets @code{BASH_ARGV} only when in extended debugging mode
  4643. (see @ref{The Shopt Builtin}
  4644. for a description of the @code{extdebug} option to the @code{shopt}
  4645. builtin).
  4646. @item BASH_CMDS
  4647. An associative array variable whose members correspond to the internal
  4648. hash table of commands as maintained by the @code{hash} builtin
  4649. (@pxref{Bourne Shell Builtins}).
  4650. Elements added to this array appear in the hash table; however,
  4651. unsetting array elements currently does not cause command names to be removed
  4652. from the hash table.
  4653. If @code{BASH_CMDS}
  4654. is unset, it loses its special properties, even if it is
  4655. subsequently reset.
  4656. @item BASH_COMMAND
  4657. The command currently being executed or about to be executed, unless the
  4658. shell is executing a command as the result of a trap,
  4659. in which case it is the command executing at the time of the trap.
  4660. @item BASH_COMPAT
  4661. The value is used to set the shell's compatibility level.
  4662. @xref{The Shopt Builtin}, for a description of the various compatibility
  4663. levels and their effects.
  4664. The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
  4665. corresponding to the desired compatibility level.
  4666. If @code{BASH_COMPAT} is unset or set to the empty string, the compatibility
  4667. level is set to the default for the current version.
  4668. If @code{BASH_COMPAT} is set to a value that is not one of the valid
  4669. compatibility levels, the shell prints an error message and sets the
  4670. compatibility level to the default for the current version.
  4671. The valid compatibility levels correspond to the compatibility options
  4672. accepted by the @code{shopt} builtin described above (for example,
  4673. @var{compat42} means that 4.2 and 42 are valid values).
  4674. The current version is also a valid value.
  4675. @item BASH_ENV
  4676. If this variable is set when Bash is invoked to execute a shell
  4677. script, its value is expanded and used as the name of a startup file
  4678. to read before executing the script. @xref{Bash Startup Files}.
  4679. @item BASH_EXECUTION_STRING
  4680. The command argument to the @option{-c} invocation option.
  4681. @item BASH_LINENO
  4682. An array variable whose members are the line numbers in source files
  4683. where each corresponding member of @var{FUNCNAME} was invoked.
  4684. @code{$@{BASH_LINENO[$i]@}} is the line number in the source file
  4685. (@code{$@{BASH_SOURCE[$i+1]@}}) where
  4686. @code{$@{FUNCNAME[$i]@}} was called (or @code{$@{BASH_LINENO[$i-1]@}} if
  4687. referenced within another shell function).
  4688. Use @code{LINENO} to obtain the current line number.
  4689. @item BASH_LOADABLES_PATH
  4690. A colon-separated list of directories in which the shell looks for
  4691. dynamically loadable builtins specified by the
  4692. @code{enable} command.
  4693. @item BASH_REMATCH
  4694. An array variable whose members are assigned by the @samp{=~} binary
  4695. operator to the @code{[[} conditional command
  4696. (@pxref{Conditional Constructs}).
  4697. The element with index 0 is the portion of the string
  4698. matching the entire regular expression.
  4699. The element with index @var{n} is the portion of the
  4700. string matching the @var{n}th parenthesized subexpression.
  4701. This variable is read-only.
  4702. @item BASH_SOURCE
  4703. An array variable whose members are the source filenames where the
  4704. corresponding shell function names in the @code{FUNCNAME} array
  4705. variable are defined.
  4706. The shell function @code{$@{FUNCNAME[$i]@}} is defined in the file
  4707. @code{$@{BASH_SOURCE[$i]@}} and called from @code{$@{BASH_SOURCE[$i+1]@}}
  4708. @item BASH_SUBSHELL
  4709. Incremented by one within each subshell or subshell environment when
  4710. the shell begins executing in that environment.
  4711. The initial value is 0.
  4712. @item BASH_VERSINFO
  4713. A readonly array variable (@pxref{Arrays})
  4714. whose members hold version information for this instance of Bash.
  4715. The values assigned to the array members are as follows:
  4716. @table @code
  4717. @item BASH_VERSINFO[0]
  4718. The major version number (the @var{release}).
  4719. @item BASH_VERSINFO[1]
  4720. The minor version number (the @var{version}).
  4721. @item BASH_VERSINFO[2]
  4722. The patch level.
  4723. @item BASH_VERSINFO[3]
  4724. The build version.
  4725. @item BASH_VERSINFO[4]
  4726. The release status (e.g., @var{beta1}).
  4727. @item BASH_VERSINFO[5]
  4728. The value of @env{MACHTYPE}.
  4729. @end table
  4730. @item BASH_VERSION
  4731. The version number of the current instance of Bash.
  4732. @item BASH_XTRACEFD
  4733. If set to an integer corresponding to a valid file descriptor, Bash
  4734. will write the trace output generated when @samp{set -x}
  4735. is enabled to that file descriptor.
  4736. This allows tracing output to be separated from diagnostic and error
  4737. messages.
  4738. The file descriptor is closed when @code{BASH_XTRACEFD} is unset or assigned
  4739. a new value.
  4740. Unsetting @code{BASH_XTRACEFD} or assigning it the empty string causes the
  4741. trace output to be sent to the standard error.
  4742. Note that setting @code{BASH_XTRACEFD} to 2 (the standard error file
  4743. descriptor) and then unsetting it will result in the standard error
  4744. being closed.
  4745. @item CHILD_MAX
  4746. Set the number of exited child status values for the shell to remember.
  4747. Bash will not allow this value to be decreased below a @sc{posix}-mandated
  4748. minimum, and there is a maximum value (currently 8192) that this may
  4749. not exceed.
  4750. The minimum value is system-dependent.
  4751. @item COLUMNS
  4752. Used by the @code{select} command to determine the terminal width
  4753. when printing selection lists.
  4754. Automatically set if the @code{checkwinsize} option is enabled
  4755. (@pxref{The Shopt Builtin}), or in an interactive shell upon receipt of a
  4756. @code{SIGWINCH}.
  4757. @item COMP_CWORD
  4758. An index into @env{$@{COMP_WORDS@}} of the word containing the current
  4759. cursor position.
  4760. This variable is available only in shell functions invoked by the
  4761. programmable completion facilities (@pxref{Programmable Completion}).
  4762. @item COMP_LINE
  4763. The current command line.
  4764. This variable is available only in shell functions and external
  4765. commands invoked by the
  4766. programmable completion facilities (@pxref{Programmable Completion}).
  4767. @item COMP_POINT
  4768. The index of the current cursor position relative to the beginning of
  4769. the current command.
  4770. If the current cursor position is at the end of the current command,
  4771. the value of this variable is equal to @code{$@{#COMP_LINE@}}.
  4772. This variable is available only in shell functions and external
  4773. commands invoked by the
  4774. programmable completion facilities (@pxref{Programmable Completion}).
  4775. @item COMP_TYPE
  4776. Set to an integer value corresponding to the type of completion attempted
  4777. that caused a completion function to be called:
  4778. @var{TAB}, for normal completion,
  4779. @samp{?}, for listing completions after successive tabs,
  4780. @samp{!}, for listing alternatives on partial word completion,
  4781. @samp{@@}, to list completions if the word is not unmodified,
  4782. or
  4783. @samp{%}, for menu completion.
  4784. This variable is available only in shell functions and external
  4785. commands invoked by the
  4786. programmable completion facilities (@pxref{Programmable Completion}).
  4787. @item COMP_KEY
  4788. The key (or final key of a key sequence) used to invoke the current
  4789. completion function.
  4790. @item COMP_WORDBREAKS
  4791. The set of characters that the Readline library treats as word
  4792. separators when performing word completion.
  4793. If @code{COMP_WORDBREAKS} is unset, it loses its special properties,
  4794. even if it is subsequently reset.
  4795. @item COMP_WORDS
  4796. An array variable consisting of the individual
  4797. words in the current command line.
  4798. The line is split into words as Readline would split it, using
  4799. @code{COMP_WORDBREAKS} as described above.
  4800. This variable is available only in shell functions invoked by the
  4801. programmable completion facilities (@pxref{Programmable Completion}).
  4802. @item COMPREPLY
  4803. An array variable from which Bash reads the possible completions
  4804. generated by a shell function invoked by the programmable completion
  4805. facility (@pxref{Programmable Completion}).
  4806. Each array element contains one possible completion.
  4807. @item COPROC
  4808. An array variable created to hold the file descriptors
  4809. for output from and input to an unnamed coprocess (@pxref{Coprocesses}).
  4810. @item DIRSTACK
  4811. An array variable containing the current contents of the directory stack.
  4812. Directories appear in the stack in the order they are displayed by the
  4813. @code{dirs} builtin.
  4814. Assigning to members of this array variable may be used to modify
  4815. directories already in the stack, but the @code{pushd} and @code{popd}
  4816. builtins must be used to add and remove directories.
  4817. Assignment to this variable will not change the current directory.
  4818. If @env{DIRSTACK} is unset, it loses its special properties, even if
  4819. it is subsequently reset.
  4820. @item EMACS
  4821. If Bash finds this variable in the environment when the shell
  4822. starts with value @samp{t}, it assumes that the shell is running in an
  4823. Emacs shell buffer and disables line editing.
  4824. @item ENV
  4825. Similar to @code{BASH_ENV}; used when the shell is invoked in
  4826. @sc{posix} Mode (@pxref{Bash POSIX Mode}).
  4827. @item EUID
  4828. The numeric effective user id of the current user. This variable
  4829. is readonly.
  4830. @item EXECIGNORE
  4831. A colon-separated list of shell patterns (@pxref{Pattern Matching})
  4832. defining the list of filenames to be ignored by command search using
  4833. @code{PATH}.
  4834. Files whose full pathnames match one of these patterns are not considered
  4835. executable files for the purposes of completion and command execution
  4836. via @code{PATH} lookup.
  4837. This does not affect the behavior of the @code{[}, @code{test}, and @code{[[}
  4838. commands.
  4839. Full pathnames in the command hash table are not subject to @code{EXECIGNORE}.
  4840. Use this variable to ignore shared library files that have the executable
  4841. bit set, but are not executable files.
  4842. The pattern matching honors the setting of the @code{extglob} shell
  4843. option.
  4844. @item FCEDIT
  4845. The editor used as a default by the @option{-e} option to the @code{fc}
  4846. builtin command.
  4847. @item FIGNORE
  4848. A colon-separated list of suffixes to ignore when performing
  4849. filename completion.
  4850. A filename whose suffix matches one of the entries in
  4851. @env{FIGNORE}
  4852. is excluded from the list of matched filenames. A sample
  4853. value is @samp{.o:~}
  4854. @item FUNCNAME
  4855. An array variable containing the names of all shell functions
  4856. currently in the execution call stack.
  4857. The element with index 0 is the name of any currently-executing
  4858. shell function.
  4859. The bottom-most element (the one with the highest index)
  4860. is @code{"main"}.
  4861. This variable exists only when a shell function is executing.
  4862. Assignments to @env{FUNCNAME} have no effect.
  4863. If @env{FUNCNAME} is unset, it loses its special properties, even if
  4864. it is subsequently reset.
  4865. This variable can be used with @code{BASH_LINENO} and @code{BASH_SOURCE}.
  4866. Each element of @code{FUNCNAME} has corresponding elements in
  4867. @code{BASH_LINENO} and @code{BASH_SOURCE} to describe the call stack.
  4868. For instance, @code{$@{FUNCNAME[$i]@}} was called from the file
  4869. @code{$@{BASH_SOURCE[$i+1]@}} at line number @code{$@{BASH_LINENO[$i]@}}.
  4870. The @code{caller} builtin displays the current call stack using this
  4871. information.
  4872. @item FUNCNEST
  4873. If set to a numeric value greater than 0, defines a maximum function
  4874. nesting level. Function invocations that exceed this nesting level
  4875. will cause the current command to abort.
  4876. @item GLOBIGNORE
  4877. A colon-separated list of patterns defining the set of filenames to
  4878. be ignored by filename expansion.
  4879. If a filename matched by a filename expansion pattern also matches one
  4880. of the patterns in @env{GLOBIGNORE}, it is removed from the list
  4881. of matches.
  4882. The pattern matching honors the setting of the @code{extglob} shell
  4883. option.
  4884. @item GROUPS
  4885. An array variable containing the list of groups of which the current
  4886. user is a member.
  4887. Assignments to @env{GROUPS} have no effect.
  4888. If @env{GROUPS} is unset, it loses its special properties, even if it is
  4889. subsequently reset.
  4890. @item histchars
  4891. Up to three characters which control history expansion, quick
  4892. substitution, and tokenization (@pxref{History Interaction}).
  4893. The first character is the
  4894. @var{history expansion} character, that is, the character which signifies the
  4895. start of a history expansion, normally @samp{!}. The second character is the
  4896. character which signifies `quick substitution' when seen as the first
  4897. character on a line, normally @samp{^}. The optional third character is the
  4898. character which indicates that the remainder of the line is a comment when
  4899. found as the first character of a word, usually @samp{#}. The history
  4900. comment character causes history substitution to be skipped for the
  4901. remaining words on the line. It does not necessarily cause the shell
  4902. parser to treat the rest of the line as a comment.
  4903. @item HISTCMD
  4904. The history number, or index in the history list, of the current
  4905. command. If @env{HISTCMD} is unset, it loses its special properties,
  4906. even if it is subsequently reset.
  4907. @item HISTCONTROL
  4908. A colon-separated list of values controlling how commands are saved on
  4909. the history list.
  4910. If the list of values includes @samp{ignorespace}, lines which begin
  4911. with a space character are not saved in the history list.
  4912. A value of @samp{ignoredups} causes lines which match the previous
  4913. history entry to not be saved.
  4914. A value of @samp{ignoreboth} is shorthand for
  4915. @samp{ignorespace} and @samp{ignoredups}.
  4916. A value of @samp{erasedups} causes all previous lines matching the
  4917. current line to be removed from the history list before that line
  4918. is saved.
  4919. Any value not in the above list is ignored.
  4920. If @env{HISTCONTROL} is unset, or does not include a valid value,
  4921. all lines read by the shell parser are saved on the history list,
  4922. subject to the value of @env{HISTIGNORE}.
  4923. The second and subsequent lines of a multi-line compound command are
  4924. not tested, and are added to the history regardless of the value of
  4925. @env{HISTCONTROL}.
  4926. @item HISTFILE
  4927. The name of the file to which the command history is saved. The
  4928. default value is @file{~/.bash_history}.
  4929. @item HISTFILESIZE
  4930. The maximum number of lines contained in the history file.
  4931. When this variable is assigned a value, the history file is truncated,
  4932. if necessary, to contain no more than that number of lines
  4933. by removing the oldest entries.
  4934. The history file is also truncated to this size after
  4935. writing it when a shell exits.
  4936. If the value is 0, the history file is truncated to zero size.
  4937. Non-numeric values and numeric values less than zero inhibit truncation.
  4938. The shell sets the default value to the value of @env{HISTSIZE}
  4939. after reading any startup files.
  4940. @item HISTIGNORE
  4941. A colon-separated list of patterns used to decide which command
  4942. lines should be saved on the history list. Each pattern is
  4943. anchored at the beginning of the line and must match the complete
  4944. line (no implicit @samp{*} is appended). Each pattern is tested
  4945. against the line after the checks specified by @env{HISTCONTROL}
  4946. are applied. In addition to the normal shell pattern matching
  4947. characters, @samp{&} matches the previous history line. @samp{&}
  4948. may be escaped using a backslash; the backslash is removed
  4949. before attempting a match.
  4950. The second and subsequent lines of a multi-line compound command are
  4951. not tested, and are added to the history regardless of the value of
  4952. @env{HISTIGNORE}.
  4953. The pattern matching honors the setting of the @code{extglob} shell
  4954. option.
  4955. @env{HISTIGNORE} subsumes the function of @env{HISTCONTROL}. A
  4956. pattern of @samp{&} is identical to @code{ignoredups}, and a
  4957. pattern of @samp{[ ]*} is identical to @code{ignorespace}.
  4958. Combining these two patterns, separating them with a colon,
  4959. provides the functionality of @code{ignoreboth}.
  4960. @item HISTSIZE
  4961. The maximum number of commands to remember on the history list.
  4962. If the value is 0, commands are not saved in the history list.
  4963. Numeric values less than zero result in every command being saved
  4964. on the history list (there is no limit).
  4965. The shell sets the default value to 500 after reading any startup files.
  4966. @item HISTTIMEFORMAT
  4967. If this variable is set and not null, its value is used as a format string
  4968. for @var{strftime} to print the time stamp associated with each history
  4969. entry displayed by the @code{history} builtin.
  4970. If this variable is set, time stamps are written to the history file so
  4971. they may be preserved across shell sessions.
  4972. This uses the history comment character to distinguish timestamps from
  4973. other history lines.
  4974. @item HOSTFILE
  4975. Contains the name of a file in the same format as @file{/etc/hosts} that
  4976. should be read when the shell needs to complete a hostname.
  4977. The list of possible hostname completions may be changed while the shell
  4978. is running;
  4979. the next time hostname completion is attempted after the
  4980. value is changed, Bash adds the contents of the new file to the
  4981. existing list.
  4982. If @env{HOSTFILE} is set, but has no value, or does not name a readable file,
  4983. Bash attempts to read
  4984. @file{/etc/hosts} to obtain the list of possible hostname completions.
  4985. When @env{HOSTFILE} is unset, the hostname list is cleared.
  4986. @item HOSTNAME
  4987. The name of the current host.
  4988. @item HOSTTYPE
  4989. A string describing the machine Bash is running on.
  4990. @item IGNOREEOF
  4991. Controls the action of the shell on receipt of an @code{EOF} character
  4992. as the sole input. If set, the value denotes the number
  4993. of consecutive @code{EOF} characters that can be read as the
  4994. first character on an input line
  4995. before the shell will exit. If the variable exists but does not
  4996. have a numeric value (or has no value) then the default is 10.
  4997. If the variable does not exist, then @code{EOF} signifies the end of
  4998. input to the shell. This is only in effect for interactive shells.
  4999. @item INPUTRC
  5000. The name of the Readline initialization file, overriding the default
  5001. of @file{~/.inputrc}.
  5002. @item LANG
  5003. Used to determine the locale category for any category not specifically
  5004. selected with a variable starting with @code{LC_}.
  5005. @item LC_ALL
  5006. This variable overrides the value of @env{LANG} and any other
  5007. @code{LC_} variable specifying a locale category.
  5008. @item LC_COLLATE
  5009. This variable determines the collation order used when sorting the
  5010. results of filename expansion, and
  5011. determines the behavior of range expressions, equivalence classes,
  5012. and collating sequences within filename expansion and pattern matching
  5013. (@pxref{Filename Expansion}).
  5014. @item LC_CTYPE
  5015. This variable determines the interpretation of characters and the
  5016. behavior of character classes within filename expansion and pattern
  5017. matching (@pxref{Filename Expansion}).
  5018. @item LC_MESSAGES
  5019. This variable determines the locale used to translate double-quoted
  5020. strings preceded by a @samp{$} (@pxref{Locale Translation}).
  5021. @item LC_NUMERIC
  5022. This variable determines the locale category used for number formatting.
  5023. @item LC_TIME
  5024. This variable determines the locale category used for data and time
  5025. formatting.
  5026. @item LINENO
  5027. The line number in the script or shell function currently executing.
  5028. @item LINES
  5029. Used by the @code{select} command to determine the column length
  5030. for printing selection lists.
  5031. Automatically set if the @code{checkwinsize} option is enabled
  5032. (@pxref{The Shopt Builtin}), or in an interactive shell upon receipt of a
  5033. @code{SIGWINCH}.
  5034. @item MACHTYPE
  5035. A string that fully describes the system type on which Bash
  5036. is executing, in the standard @sc{gnu} @var{cpu-company-system} format.
  5037. @item MAILCHECK
  5038. How often (in seconds) that the shell should check for mail in the
  5039. files specified in the @env{MAILPATH} or @env{MAIL} variables.
  5040. The default is 60 seconds. When it is time to check
  5041. for mail, the shell does so before displaying the primary prompt.
  5042. If this variable is unset, or set to a value that is not a number
  5043. greater than or equal to zero, the shell disables mail checking.
  5044. @item MAPFILE
  5045. An array variable created to hold the text read by the
  5046. @code{mapfile} builtin when no variable name is supplied.
  5047. @item OLDPWD
  5048. The previous working directory as set by the @code{cd} builtin.
  5049. @item OPTERR
  5050. If set to the value 1, Bash displays error messages
  5051. generated by the @code{getopts} builtin command.
  5052. @item OSTYPE
  5053. A string describing the operating system Bash is running on.
  5054. @item PIPESTATUS
  5055. An array variable (@pxref{Arrays})
  5056. containing a list of exit status values from the processes
  5057. in the most-recently-executed foreground pipeline (which may
  5058. contain only a single command).
  5059. @item POSIXLY_CORRECT
  5060. If this variable is in the environment when Bash starts, the shell
  5061. enters @sc{posix} mode (@pxref{Bash POSIX Mode}) before reading the
  5062. startup files, as if the @option{--posix} invocation option had been supplied.
  5063. If it is set while the shell is running, Bash enables @sc{posix} mode,
  5064. as if the command
  5065. @example
  5066. @code{set -o posix}
  5067. @end example
  5068. @noindent
  5069. had been executed.
  5070. @item PPID
  5071. The process @sc{id} of the shell's parent process. This variable
  5072. is readonly.
  5073. @item PROMPT_COMMAND
  5074. If set, the value is interpreted as a command to execute
  5075. before the printing of each primary prompt (@env{$PS1}).
  5076. @item PROMPT_DIRTRIM
  5077. If set to a number greater than zero, the value is used as the number of
  5078. trailing directory components to retain when expanding the @code{\w} and
  5079. @code{\W} prompt string escapes (@pxref{Controlling the Prompt}).
  5080. Characters removed are replaced with an ellipsis.
  5081. @item PS0
  5082. The value of this parameter is expanded like @var{PS1}
  5083. and displayed by interactive shells after reading a command
  5084. and before the command is executed.
  5085. @item PS3
  5086. The value of this variable is used as the prompt for the
  5087. @code{select} command. If this variable is not set, the
  5088. @code{select} command prompts with @samp{#? }
  5089. @item PS4
  5090. The value is the prompt printed before the command line is echoed
  5091. when the @option{-x} option is set (@pxref{The Set Builtin}).
  5092. The first character of @env{PS4} is replicated multiple times, as
  5093. necessary, to indicate multiple levels of indirection.
  5094. The default is @samp{+ }.
  5095. @item PWD
  5096. The current working directory as set by the @code{cd} builtin.
  5097. @item RANDOM
  5098. Each time this parameter is referenced, a random integer
  5099. between 0 and 32767 is generated. Assigning a value to this
  5100. variable seeds the random number generator.
  5101. @item READLINE_LINE
  5102. The contents of the Readline line buffer, for use
  5103. with @samp{bind -x} (@pxref{Bash Builtins}).
  5104. @item READLINE_POINT
  5105. The position of the insertion point in the Readline line buffer, for use
  5106. with @samp{bind -x} (@pxref{Bash Builtins}).
  5107. @item REPLY
  5108. The default variable for the @code{read} builtin.
  5109. @item SECONDS
  5110. This variable expands to the number of seconds since the
  5111. shell was started. Assignment to this variable resets
  5112. the count to the value assigned, and the expanded value
  5113. becomes the value assigned plus the number of seconds
  5114. since the assignment.
  5115. @item SHELL
  5116. The full pathname to the shell is kept in this environment variable.
  5117. If it is not set when the shell starts,
  5118. Bash assigns to it the full pathname of the current user's login shell.
  5119. @item SHELLOPTS
  5120. A colon-separated list of enabled shell options. Each word in
  5121. the list is a valid argument for the @option{-o} option to the
  5122. @code{set} builtin command (@pxref{The Set Builtin}).
  5123. The options appearing in @env{SHELLOPTS} are those reported
  5124. as @samp{on} by @samp{set -o}.
  5125. If this variable is in the environment when Bash
  5126. starts up, each shell option in the list will be enabled before
  5127. reading any startup files. This variable is readonly.
  5128. @item SHLVL
  5129. Incremented by one each time a new instance of Bash is started. This is
  5130. intended to be a count of how deeply your Bash shells are nested.
  5131. @item TIMEFORMAT
  5132. The value of this parameter is used as a format string specifying
  5133. how the timing information for pipelines prefixed with the @code{time}
  5134. reserved word should be displayed.
  5135. The @samp{%} character introduces an
  5136. escape sequence that is expanded to a time value or other
  5137. information.
  5138. The escape sequences and their meanings are as
  5139. follows; the braces denote optional portions.
  5140. @table @code
  5141. @item %%
  5142. A literal @samp{%}.
  5143. @item %[@var{p}][l]R
  5144. The elapsed time in seconds.
  5145. @item %[@var{p}][l]U
  5146. The number of CPU seconds spent in user mode.
  5147. @item %[@var{p}][l]S
  5148. The number of CPU seconds spent in system mode.
  5149. @item %P
  5150. The CPU percentage, computed as (%U + %S) / %R.
  5151. @end table
  5152. The optional @var{p} is a digit specifying the precision, the number of
  5153. fractional digits after a decimal point.
  5154. A value of 0 causes no decimal point or fraction to be output.
  5155. At most three places after the decimal point may be specified; values
  5156. of @var{p} greater than 3 are changed to 3.
  5157. If @var{p} is not specified, the value 3 is used.
  5158. The optional @code{l} specifies a longer format, including minutes, of
  5159. the form @var{MM}m@var{SS}.@var{FF}s.
  5160. The value of @var{p} determines whether or not the fraction is included.
  5161. If this variable is not set, Bash acts as if it had the value
  5162. @example
  5163. @code{$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'}
  5164. @end example
  5165. If the value is null, no timing information is displayed.
  5166. A trailing newline is added when the format string is displayed.
  5167. @item TMOUT
  5168. If set to a value greater than zero, @code{TMOUT} is treated as the
  5169. default timeout for the @code{read} builtin (@pxref{Bash Builtins}).
  5170. The @code{select} command (@pxref{Conditional Constructs}) terminates
  5171. if input does not arrive after @code{TMOUT} seconds when input is coming
  5172. from a terminal.
  5173. In an interactive shell, the value is interpreted as
  5174. the number of seconds to wait for a line of input after issuing
  5175. the primary prompt.
  5176. Bash
  5177. terminates after waiting for that number of seconds if a complete
  5178. line of input does not arrive.
  5179. @item TMPDIR
  5180. If set, Bash uses its value as the name of a directory in which
  5181. Bash creates temporary files for the shell's use.
  5182. @item UID
  5183. The numeric real user id of the current user. This variable is readonly.
  5184. @end vtable
  5185. @node Bash Features
  5186. @chapter Bash Features
  5187. This chapter describes features unique to Bash.
  5188. @menu
  5189. * Invoking Bash:: Command line options that you can give
  5190. to Bash.
  5191. * Bash Startup Files:: When and how Bash executes scripts.
  5192. * Interactive Shells:: What an interactive shell is.
  5193. * Bash Conditional Expressions:: Primitives used in composing expressions for
  5194. the @code{test} builtin.
  5195. * Shell Arithmetic:: Arithmetic on shell variables.
  5196. * Aliases:: Substituting one command for another.
  5197. * Arrays:: Array Variables.
  5198. * The Directory Stack:: History of visited directories.
  5199. * Controlling the Prompt:: Customizing the various prompt strings.
  5200. * The Restricted Shell:: A more controlled mode of shell execution.
  5201. * Bash POSIX Mode:: Making Bash behave more closely to what
  5202. the POSIX standard specifies.
  5203. @end menu
  5204. @node Invoking Bash
  5205. @section Invoking Bash
  5206. @example
  5207. bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] [@var{argument} @dots{}]
  5208. bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] -c @var{string} [@var{argument} @dots{}]
  5209. bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] [@var{argument} @dots{}]
  5210. @end example
  5211. All of the single-character options used with the @code{set} builtin
  5212. (@pxref{The Set Builtin}) can be used as options when the shell is invoked.
  5213. In addition, there are several multi-character
  5214. options that you can use. These options must appear on the command
  5215. line before the single-character options to be recognized.
  5216. @table @code
  5217. @item --debugger
  5218. Arrange for the debugger profile to be executed before the shell
  5219. starts. Turns on extended debugging mode (see @ref{The Shopt Builtin}
  5220. for a description of the @code{extdebug} option to the @code{shopt}
  5221. builtin).
  5222. @item --dump-po-strings
  5223. A list of all double-quoted strings preceded by @samp{$}
  5224. is printed on the standard output
  5225. in the @sc{gnu} @code{gettext} PO (portable object) file format.
  5226. Equivalent to @option{-D} except for the output format.
  5227. @item --dump-strings
  5228. Equivalent to @option{-D}.
  5229. @item --help
  5230. Display a usage message on standard output and exit successfully.
  5231. @item --init-file @var{filename}
  5232. @itemx --rcfile @var{filename}
  5233. Execute commands from @var{filename} (instead of @file{~/.bashrc})
  5234. in an interactive shell.
  5235. @item --login
  5236. Equivalent to @option{-l}.
  5237. @item --noediting
  5238. Do not use the @sc{gnu} Readline library (@pxref{Command Line Editing})
  5239. to read command lines when the shell is interactive.
  5240. @item --noprofile
  5241. Don't load the system-wide startup file @file{/etc/profile}
  5242. or any of the personal initialization files
  5243. @file{~/.bash_profile}, @file{~/.bash_login}, or @file{~/.profile}
  5244. when Bash is invoked as a login shell.
  5245. @item --norc
  5246. Don't read the @file{~/.bashrc} initialization file in an
  5247. interactive shell. This is on by default if the shell is
  5248. invoked as @code{sh}.
  5249. @item --posix
  5250. Change the behavior of Bash where the default operation differs
  5251. from the @sc{posix} standard to match the standard. This
  5252. is intended to make Bash behave as a strict superset of that
  5253. standard. @xref{Bash POSIX Mode}, for a description of the Bash
  5254. @sc{posix} mode.
  5255. @item --restricted
  5256. Make the shell a restricted shell (@pxref{The Restricted Shell}).
  5257. @item --verbose
  5258. Equivalent to @option{-v}. Print shell input lines as they're read.
  5259. @item --version
  5260. Show version information for this instance of
  5261. Bash on the standard output and exit successfully.
  5262. @end table
  5263. There are several single-character options that may be supplied at
  5264. invocation which are not available with the @code{set} builtin.
  5265. @table @code
  5266. @item -c
  5267. Read and execute commands from the first non-option argument
  5268. @var{command_string}, then exit.
  5269. If there are arguments after the @var{command_string},
  5270. the first argument is assigned to @code{$0}
  5271. and any remaining arguments are assigned to the positional parameters.
  5272. The assignment to @code{$0} sets the name of the shell, which is used
  5273. in warning and error messages.
  5274. @item -i
  5275. Force the shell to run interactively. Interactive shells are
  5276. described in @ref{Interactive Shells}.
  5277. @item -l
  5278. Make this shell act as if it had been directly invoked by login.
  5279. When the shell is interactive, this is equivalent to starting a
  5280. login shell with @samp{exec -l bash}.
  5281. When the shell is not interactive, the login shell startup files will
  5282. be executed.
  5283. @samp{exec bash -l} or @samp{exec bash --login}
  5284. will replace the current shell with a Bash login shell.
  5285. @xref{Bash Startup Files}, for a description of the special behavior
  5286. of a login shell.
  5287. @item -r
  5288. Make the shell a restricted shell (@pxref{The Restricted Shell}).
  5289. @item -s
  5290. If this option is present, or if no arguments remain after option
  5291. processing, then commands are read from the standard input.
  5292. This option allows the positional parameters to be set
  5293. when invoking an interactive shell.
  5294. @item -D
  5295. A list of all double-quoted strings preceded by @samp{$}
  5296. is printed on the standard output.
  5297. These are the strings that
  5298. are subject to language translation when the current locale
  5299. is not @code{C} or @code{POSIX} (@pxref{Locale Translation}).
  5300. This implies the @option{-n} option; no commands will be executed.
  5301. @item [-+]O [@var{shopt_option}]
  5302. @var{shopt_option} is one of the shell options accepted by the
  5303. @code{shopt} builtin (@pxref{The Shopt Builtin}).
  5304. If @var{shopt_option} is present, @option{-O} sets the value of that option;
  5305. @option{+O} unsets it.
  5306. If @var{shopt_option} is not supplied, the names and values of the shell
  5307. options accepted by @code{shopt} are printed on the standard output.
  5308. If the invocation option is @option{+O}, the output is displayed in a format
  5309. that may be reused as input.
  5310. @item --
  5311. A @code{--} signals the end of options and disables further option
  5312. processing.
  5313. Any arguments after the @code{--} are treated as filenames and arguments.
  5314. @end table
  5315. @cindex login shell
  5316. A @emph{login} shell is one whose first character of argument zero is
  5317. @samp{-}, or one invoked with the @option{--login} option.
  5318. @cindex interactive shell
  5319. An @emph{interactive} shell is one started without non-option arguments,
  5320. unless @option{-s} is specified,
  5321. without specifying the @option{-c} option, and whose input and output are both
  5322. connected to terminals (as determined by @code{isatty(3)}), or one
  5323. started with the @option{-i} option. @xref{Interactive Shells}, for more
  5324. information.
  5325. If arguments remain after option processing, and neither the
  5326. @option{-c} nor the @option{-s}
  5327. option has been supplied, the first argument is assumed to
  5328. be the name of a file containing shell commands (@pxref{Shell Scripts}).
  5329. When Bash is invoked in this fashion, @code{$0}
  5330. is set to the name of the file, and the positional parameters
  5331. are set to the remaining arguments.
  5332. Bash reads and executes commands from this file, then exits.
  5333. Bash's exit status is the exit status of the last command executed
  5334. in the script. If no commands are executed, the exit status is 0.
  5335. @node Bash Startup Files
  5336. @section Bash Startup Files
  5337. @cindex startup files
  5338. This section describes how Bash executes its startup files.
  5339. If any of the files exist but cannot be read, Bash reports an error.
  5340. Tildes are expanded in filenames as described above under
  5341. Tilde Expansion (@pxref{Tilde Expansion}).
  5342. Interactive shells are described in @ref{Interactive Shells}.
  5343. @subsubheading Invoked as an interactive login shell, or with @option{--login}
  5344. When Bash is invoked as an interactive login shell, or as a
  5345. non-interactive shell with the @option{--login} option, it first reads and
  5346. executes commands from the file @file{/etc/profile}, if that file exists.
  5347. After reading that file, it looks for @file{~/.bash_profile},
  5348. @file{~/.bash_login}, and @file{~/.profile}, in that order, and reads
  5349. and executes commands from the first one that exists and is readable.
  5350. The @option{--noprofile} option may be used when the shell is started to
  5351. inhibit this behavior.
  5352. When an interactive login shell exits,
  5353. or a non-interactive login shell executes the @code{exit} builtin command,
  5354. Bash reads and executes commands from
  5355. the file @file{~/.bash_logout}, if it exists.
  5356. @subsubheading Invoked as an interactive non-login shell
  5357. When an interactive shell that is not a login shell is started, Bash
  5358. reads and executes commands from @file{~/.bashrc}, if that file exists.
  5359. This may be inhibited by using the @option{--norc} option.
  5360. The @option{--rcfile @var{file}} option will force Bash to read and
  5361. execute commands from @var{file} instead of @file{~/.bashrc}.
  5362. So, typically, your @file{~/.bash_profile} contains the line
  5363. @example
  5364. @code{if [ -f ~/.bashrc ]; then . ~/.bashrc; fi}
  5365. @end example
  5366. @noindent
  5367. after (or before) any login-specific initializations.
  5368. @subsubheading Invoked non-interactively
  5369. When Bash is started non-interactively, to run a shell script,
  5370. for example, it looks for the variable @env{BASH_ENV} in the environment,
  5371. expands its value if it appears there, and uses the expanded value as
  5372. the name of a file to read and execute. Bash behaves as if the
  5373. following command were executed:
  5374. @example
  5375. @code{if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi}
  5376. @end example
  5377. @noindent
  5378. but the value of the @env{PATH} variable is not used to search for the
  5379. filename.
  5380. As noted above, if a non-interactive shell is invoked with the
  5381. @option{--login} option, Bash attempts to read and execute commands from the
  5382. login shell startup files.
  5383. @subsubheading Invoked with name @code{sh}
  5384. If Bash is invoked with the name @code{sh}, it tries to mimic the
  5385. startup behavior of historical versions of @code{sh} as closely as
  5386. possible, while conforming to the @sc{posix} standard as well.
  5387. When invoked as an interactive login shell, or as a non-interactive
  5388. shell with the @option{--login} option, it first attempts to read
  5389. and execute commands from @file{/etc/profile} and @file{~/.profile}, in
  5390. that order.
  5391. The @option{--noprofile} option may be used to inhibit this behavior.
  5392. When invoked as an interactive shell with the name @code{sh}, Bash
  5393. looks for the variable @env{ENV}, expands its value if it is defined,
  5394. and uses the expanded value as the name of a file to read and execute.
  5395. Since a shell invoked as @code{sh} does not attempt to read and execute
  5396. commands from any other startup files, the @option{--rcfile} option has
  5397. no effect.
  5398. A non-interactive shell invoked with the name @code{sh} does not attempt
  5399. to read any other startup files.
  5400. When invoked as @code{sh}, Bash enters @sc{posix} mode after
  5401. the startup files are read.
  5402. @subsubheading Invoked in @sc{posix} mode
  5403. When Bash is started in @sc{posix} mode, as with the
  5404. @option{--posix} command line option, it follows the @sc{posix} standard
  5405. for startup files.
  5406. In this mode, interactive shells expand the @env{ENV} variable
  5407. and commands are read and executed from the file whose name is the
  5408. expanded value.
  5409. No other startup files are read.
  5410. @subsubheading Invoked by remote shell daemon
  5411. Bash attempts to determine when it is being run with its standard input
  5412. connected to a network connection, as when executed by the remote shell
  5413. daemon, usually @code{rshd}, or the secure shell daemon @code{sshd}.
  5414. If Bash determines it is being run in
  5415. this fashion, it reads and executes commands from @file{~/.bashrc}, if that
  5416. file exists and is readable.
  5417. It will not do this if invoked as @code{sh}.
  5418. The @option{--norc} option may be used to inhibit this behavior, and the
  5419. @option{--rcfile} option may be used to force another file to be read, but
  5420. neither @code{rshd} nor @code{sshd} generally invoke the shell with those
  5421. options or allow them to be specified.
  5422. @subsubheading Invoked with unequal effective and real @sc{uid/gid}s
  5423. If Bash is started with the effective user (group) id not equal to the
  5424. real user (group) id, and the @option{-p} option is not supplied, no startup
  5425. files are read, shell functions are not inherited from the environment,
  5426. the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH}, and @env{GLOBIGNORE}
  5427. variables, if they appear in the environment, are ignored, and the effective
  5428. user id is set to the real user id.
  5429. If the @option{-p} option is supplied at invocation, the startup behavior is
  5430. the same, but the effective user id is not reset.
  5431. @node Interactive Shells
  5432. @section Interactive Shells
  5433. @cindex interactive shell
  5434. @cindex shell, interactive
  5435. @menu
  5436. * What is an Interactive Shell?:: What determines whether a shell is Interactive.
  5437. * Is this Shell Interactive?:: How to tell if a shell is interactive.
  5438. * Interactive Shell Behavior:: What changes in a interactive shell?
  5439. @end menu
  5440. @node What is an Interactive Shell?
  5441. @subsection What is an Interactive Shell?
  5442. An interactive shell
  5443. is one started without non-option arguments, unless @option{-s} is
  5444. specified, without specifying the @option{-c} option, and
  5445. whose input and error output are both
  5446. connected to terminals (as determined by @code{isatty(3)}),
  5447. or one started with the @option{-i} option.
  5448. An interactive shell generally reads from and writes to a user's
  5449. terminal.
  5450. The @option{-s} invocation option may be used to set the positional parameters
  5451. when an interactive shell is started.
  5452. @node Is this Shell Interactive?
  5453. @subsection Is this Shell Interactive?
  5454. To determine within a startup script whether or not Bash is
  5455. running interactively,
  5456. test the value of the @samp{-} special parameter.
  5457. It contains @code{i} when the shell is interactive. For example:
  5458. @example
  5459. case "$-" in
  5460. *i*) echo This shell is interactive ;;
  5461. *) echo This shell is not interactive ;;
  5462. esac
  5463. @end example
  5464. Alternatively, startup scripts may examine the variable
  5465. @env{PS1}; it is unset in non-interactive shells, and set in
  5466. interactive shells. Thus:
  5467. @example
  5468. if [ -z "$PS1" ]; then
  5469. echo This shell is not interactive
  5470. else
  5471. echo This shell is interactive
  5472. fi
  5473. @end example
  5474. @node Interactive Shell Behavior
  5475. @subsection Interactive Shell Behavior
  5476. When the shell is running interactively, it changes its behavior in
  5477. several ways.
  5478. @enumerate
  5479. @item
  5480. Startup files are read and executed as described in @ref{Bash Startup Files}.
  5481. @item
  5482. Job Control (@pxref{Job Control}) is enabled by default. When job
  5483. control is in effect, Bash ignores the keyboard-generated job control
  5484. signals @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
  5485. @item
  5486. Bash expands and displays @env{PS1} before reading the first line
  5487. of a command, and expands and displays @env{PS2} before reading the
  5488. second and subsequent lines of a multi-line command.
  5489. Bash displays @env{PS0} after it reads a command but before executing it.
  5490. @item
  5491. Bash executes the value of the @env{PROMPT_COMMAND} variable as a command
  5492. before printing the primary prompt, @env{$PS1}
  5493. (@pxref{Bash Variables}).
  5494. @item
  5495. Readline (@pxref{Command Line Editing}) is used to read commands from
  5496. the user's terminal.
  5497. @item
  5498. Bash inspects the value of the @code{ignoreeof} option to @code{set -o}
  5499. instead of exiting immediately when it receives an @code{EOF} on its
  5500. standard input when reading a command (@pxref{The Set Builtin}).
  5501. @item
  5502. Command history (@pxref{Bash History Facilities})
  5503. and history expansion (@pxref{History Interaction})
  5504. are enabled by default.
  5505. Bash will save the command history to the file named by @env{$HISTFILE}
  5506. when a shell with history enabled exits.
  5507. @item
  5508. Alias expansion (@pxref{Aliases}) is performed by default.
  5509. @item
  5510. In the absence of any traps, Bash ignores @code{SIGTERM}
  5511. (@pxref{Signals}).
  5512. @item
  5513. In the absence of any traps, @code{SIGINT} is caught and handled
  5514. ((@pxref{Signals}).
  5515. @code{SIGINT} will interrupt some shell builtins.
  5516. @item
  5517. An interactive login shell sends a @code{SIGHUP} to all jobs on exit
  5518. if the @code{huponexit} shell option has been enabled (@pxref{Signals}).
  5519. @item
  5520. The @option{-n} invocation option is ignored, and @samp{set -n} has
  5521. no effect (@pxref{The Set Builtin}).
  5522. @item
  5523. Bash will check for mail periodically, depending on the values of the
  5524. @env{MAIL}, @env{MAILPATH}, and @env{MAILCHECK} shell variables
  5525. (@pxref{Bash Variables}).
  5526. @item
  5527. Expansion errors due to references to unbound shell variables after
  5528. @samp{set -u} has been enabled will not cause the shell to exit
  5529. (@pxref{The Set Builtin}).
  5530. @item
  5531. The shell will not exit on expansion errors caused by @var{var} being unset
  5532. or null in @code{$@{@var{var}:?@var{word}@}} expansions
  5533. (@pxref{Shell Parameter Expansion}).
  5534. @item
  5535. Redirection errors encountered by shell builtins will not cause the
  5536. shell to exit.
  5537. @item
  5538. When running in @sc{posix} mode, a special builtin returning an error
  5539. status will not cause the shell to exit (@pxref{Bash POSIX Mode}).
  5540. @item
  5541. A failed @code{exec} will not cause the shell to exit
  5542. (@pxref{Bourne Shell Builtins}).
  5543. @item
  5544. Parser syntax errors will not cause the shell to exit.
  5545. @item
  5546. Simple spelling correction for directory arguments to the @code{cd}
  5547. builtin is enabled by default (see the description of the @code{cdspell}
  5548. option to the @code{shopt} builtin in @ref{The Shopt Builtin}).
  5549. @item
  5550. The shell will check the value of the @env{TMOUT} variable and exit
  5551. if a command is not read within the specified number of seconds after
  5552. printing @env{$PS1} (@pxref{Bash Variables}).
  5553. @end enumerate
  5554. @node Bash Conditional Expressions
  5555. @section Bash Conditional Expressions
  5556. @cindex expressions, conditional
  5557. Conditional expressions are used by the @code{[[} compound command
  5558. and the @code{test} and @code{[} builtin commands.
  5559. Expressions may be unary or binary.
  5560. Unary expressions are often used to examine the status of a file.
  5561. There are string operators and numeric comparison operators as well.
  5562. Bash handles several filenames specially when they are used in
  5563. expressions.
  5564. If the operating system on which Bash is running provides these
  5565. special files, Bash will use them; otherwise it will emulate them
  5566. internally with this behavior:
  5567. If the @var{file} argument to one of the primaries is of the form
  5568. @file{/dev/fd/@var{N}}, then file descriptor @var{N} is checked.
  5569. If the @var{file} argument to one of the primaries is one of
  5570. @file{/dev/stdin}, @file{/dev/stdout}, or @file{/dev/stderr}, file
  5571. descriptor 0, 1, or 2, respectively, is checked.
  5572. When used with @code{[[}, the @samp{<} and @samp{>} operators sort
  5573. lexicographically using the current locale.
  5574. The @code{test} command uses ASCII ordering.
  5575. Unless otherwise specified, primaries that operate on files follow symbolic
  5576. links and operate on the target of the link, rather than the link itself.
  5577. @table @code
  5578. @item -a @var{file}
  5579. True if @var{file} exists.
  5580. @item -b @var{file}
  5581. True if @var{file} exists and is a block special file.
  5582. @item -c @var{file}
  5583. True if @var{file} exists and is a character special file.
  5584. @item -d @var{file}
  5585. True if @var{file} exists and is a directory.
  5586. @item -e @var{file}
  5587. True if @var{file} exists.
  5588. @item -f @var{file}
  5589. True if @var{file} exists and is a regular file.
  5590. @item -g @var{file}
  5591. True if @var{file} exists and its set-group-id bit is set.
  5592. @item -h @var{file}
  5593. True if @var{file} exists and is a symbolic link.
  5594. @item -k @var{file}
  5595. True if @var{file} exists and its "sticky" bit is set.
  5596. @item -p @var{file}
  5597. True if @var{file} exists and is a named pipe (FIFO).
  5598. @item -r @var{file}
  5599. True if @var{file} exists and is readable.
  5600. @item -s @var{file}
  5601. True if @var{file} exists and has a size greater than zero.
  5602. @item -t @var{fd}
  5603. True if file descriptor @var{fd} is open and refers to a terminal.
  5604. @item -u @var{file}
  5605. True if @var{file} exists and its set-user-id bit is set.
  5606. @item -w @var{file}
  5607. True if @var{file} exists and is writable.
  5608. @item -x @var{file}
  5609. True if @var{file} exists and is executable.
  5610. @item -G @var{file}
  5611. True if @var{file} exists and is owned by the effective group id.
  5612. @item -L @var{file}
  5613. True if @var{file} exists and is a symbolic link.
  5614. @item -N @var{file}
  5615. True if @var{file} exists and has been modified since it was last read.
  5616. @item -O @var{file}
  5617. True if @var{file} exists and is owned by the effective user id.
  5618. @item -S @var{file}
  5619. True if @var{file} exists and is a socket.
  5620. @item @var{file1} -ef @var{file2}
  5621. True if @var{file1} and @var{file2} refer to the same device and
  5622. inode numbers.
  5623. @item @var{file1} -nt @var{file2}
  5624. True if @var{file1} is newer (according to modification date)
  5625. than @var{file2}, or if @var{file1} exists and @var{file2} does not.
  5626. @item @var{file1} -ot @var{file2}
  5627. True if @var{file1} is older than @var{file2},
  5628. or if @var{file2} exists and @var{file1} does not.
  5629. @item -o @var{optname}
  5630. True if the shell option @var{optname} is enabled.
  5631. The list of options appears in the description of the @option{-o}
  5632. option to the @code{set} builtin (@pxref{The Set Builtin}).
  5633. @item -v @var{varname}
  5634. True if the shell variable @var{varname} is set (has been assigned a value).
  5635. @item -R @var{varname}
  5636. True if the shell variable @var{varname} is set and is a name reference.
  5637. @item -z @var{string}
  5638. True if the length of @var{string} is zero.
  5639. @item -n @var{string}
  5640. @itemx @var{string}
  5641. True if the length of @var{string} is non-zero.
  5642. @item @var{string1} == @var{string2}
  5643. @itemx @var{string1} = @var{string2}
  5644. True if the strings are equal.
  5645. When used with the @code{[[} command, this performs pattern matching as
  5646. described above (@pxref{Conditional Constructs}).
  5647. @samp{=} should be used with the @code{test} command for @sc{posix} conformance.
  5648. @item @var{string1} != @var{string2}
  5649. True if the strings are not equal.
  5650. @item @var{string1} < @var{string2}
  5651. True if @var{string1} sorts before @var{string2} lexicographically.
  5652. @item @var{string1} > @var{string2}
  5653. True if @var{string1} sorts after @var{string2} lexicographically.
  5654. @item @var{arg1} OP @var{arg2}
  5655. @code{OP} is one of
  5656. @samp{-eq}, @samp{-ne}, @samp{-lt}, @samp{-le}, @samp{-gt}, or @samp{-ge}.
  5657. These arithmetic binary operators return true if @var{arg1}
  5658. is equal to, not equal to, less than, less than or equal to,
  5659. greater than, or greater than or equal to @var{arg2},
  5660. respectively. @var{Arg1} and @var{arg2}
  5661. may be positive or negative integers.
  5662. @end table
  5663. @node Shell Arithmetic
  5664. @section Shell Arithmetic
  5665. @cindex arithmetic, shell
  5666. @cindex shell arithmetic
  5667. @cindex expressions, arithmetic
  5668. @cindex evaluation, arithmetic
  5669. @cindex arithmetic evaluation
  5670. The shell allows arithmetic expressions to be evaluated, as one of
  5671. the shell expansions or by using the @code{((} compound command, the
  5672. @code{let} builtin, or the @option{-i} option to the @code{declare} builtin.
  5673. Evaluation is done in fixed-width integers with no check for overflow,
  5674. though division by 0 is trapped and flagged as an error.
  5675. The operators and their precedence, associativity, and values
  5676. are the same as in the C language.
  5677. The following list of operators is grouped into levels of
  5678. equal-precedence operators.
  5679. The levels are listed in order of decreasing precedence.
  5680. @table @code
  5681. @item @var{id}++ @var{id}--
  5682. variable post-increment and post-decrement
  5683. @item ++@var{id} --@var{id}
  5684. variable pre-increment and pre-decrement
  5685. @item - +
  5686. unary minus and plus
  5687. @item ! ~
  5688. logical and bitwise negation
  5689. @item **
  5690. exponentiation
  5691. @item * / %
  5692. multiplication, division, remainder
  5693. @item + -
  5694. addition, subtraction
  5695. @item << >>
  5696. left and right bitwise shifts
  5697. @item <= >= < >
  5698. comparison
  5699. @item == !=
  5700. equality and inequality
  5701. @item &
  5702. bitwise AND
  5703. @item ^
  5704. bitwise exclusive OR
  5705. @item |
  5706. bitwise OR
  5707. @item &&
  5708. logical AND
  5709. @item ||
  5710. logical OR
  5711. @item expr ? expr : expr
  5712. conditional operator
  5713. @item = *= /= %= += -= <<= >>= &= ^= |=
  5714. assignment
  5715. @item expr1 , expr2
  5716. comma
  5717. @end table
  5718. Shell variables are allowed as operands; parameter expansion is
  5719. performed before the expression is evaluated.
  5720. Within an expression, shell variables may also be referenced by name
  5721. without using the parameter expansion syntax.
  5722. A shell variable that is null or unset evaluates to 0 when referenced
  5723. by name without using the parameter expansion syntax.
  5724. The value of a variable is evaluated as an arithmetic expression
  5725. when it is referenced, or when a variable which has been given the
  5726. @var{integer} attribute using @samp{declare -i} is assigned a value.
  5727. A null value evaluates to 0.
  5728. A shell variable need not have its @var{integer} attribute turned on
  5729. to be used in an expression.
  5730. Constants with a leading 0 are interpreted as octal numbers.
  5731. A leading @samp{0x} or @samp{0X} denotes hexadecimal. Otherwise,
  5732. numbers take the form [@var{base}@code{#}]@var{n}, where the optional @var{base}
  5733. is a decimal number between 2 and 64 representing the arithmetic
  5734. base, and @var{n} is a number in that base.
  5735. If @var{base}@code{#} is omitted, then base 10 is used.
  5736. When specifying @var{n},
  5737. the digits greater than 9 are represented by the lowercase letters,
  5738. the uppercase letters, @samp{@@}, and @samp{_}, in that order.
  5739. If @var{base} is less than or equal to 36, lowercase and uppercase
  5740. letters may be used interchangeably to represent numbers between 10
  5741. and 35.
  5742. Operators are evaluated in order of precedence. Sub-expressions in
  5743. parentheses are evaluated first and may override the precedence
  5744. rules above.
  5745. @node Aliases
  5746. @section Aliases
  5747. @cindex alias expansion
  5748. @var{Aliases} allow a string to be substituted for a word when it is used
  5749. as the first word of a simple command.
  5750. The shell maintains a list of aliases that may be set and unset with
  5751. the @code{alias} and @code{unalias} builtin commands.
  5752. The first word of each simple command, if unquoted, is checked to see
  5753. if it has an alias.
  5754. If so, that word is replaced by the text of the alias.
  5755. The characters @samp{/}, @samp{$}, @samp{`}, @samp{=} and any of the
  5756. shell metacharacters or quoting characters listed above may not appear
  5757. in an alias name.
  5758. The replacement text may contain any valid
  5759. shell input, including shell metacharacters.
  5760. The first word of the replacement text is tested for
  5761. aliases, but a word that is identical to an alias being expanded
  5762. is not expanded a second time.
  5763. This means that one may alias @code{ls} to @code{"ls -F"},
  5764. for instance, and Bash does not try to recursively expand the
  5765. replacement text.
  5766. If the last character of the alias value is a
  5767. @var{blank}, then the next command word following the
  5768. alias is also checked for alias expansion.
  5769. Aliases are created and listed with the @code{alias}
  5770. command, and removed with the @code{unalias} command.
  5771. There is no mechanism for using arguments in the replacement text,
  5772. as in @code{csh}.
  5773. If arguments are needed, a shell function should be used
  5774. (@pxref{Shell Functions}).
  5775. Aliases are not expanded when the shell is not interactive,
  5776. unless the @code{expand_aliases} shell option is set using
  5777. @code{shopt} (@pxref{The Shopt Builtin}).
  5778. The rules concerning the definition and use of aliases are
  5779. somewhat confusing. Bash
  5780. always reads at least one complete line
  5781. of input before executing any
  5782. of the commands on that line. Aliases are expanded when a
  5783. command is read, not when it is executed. Therefore, an
  5784. alias definition appearing on the same line as another
  5785. command does not take effect until the next line of input is read.
  5786. The commands following the alias definition
  5787. on that line are not affected by the new alias.
  5788. This behavior is also an issue when functions are executed.
  5789. Aliases are expanded when a function definition is read,
  5790. not when the function is executed, because a function definition
  5791. is itself a command. As a consequence, aliases
  5792. defined in a function are not available until after that
  5793. function is executed. To be safe, always put
  5794. alias definitions on a separate line, and do not use @code{alias}
  5795. in compound commands.
  5796. For almost every purpose, shell functions are preferred over aliases.
  5797. @node Arrays
  5798. @section Arrays
  5799. @cindex arrays
  5800. Bash provides one-dimensional indexed and associative array variables.
  5801. Any variable may be used as an indexed array;
  5802. the @code{declare} builtin will explicitly declare an array.
  5803. There is no maximum
  5804. limit on the size of an array, nor any requirement that members
  5805. be indexed or assigned contiguously.
  5806. Indexed arrays are referenced using integers (including arithmetic
  5807. expressions (@pxref{Shell Arithmetic})) and are zero-based;
  5808. associative arrays use arbitrary strings.
  5809. Unless otherwise noted, indexed array indices must be non-negative integers.
  5810. An indexed array is created automatically if any variable is assigned to
  5811. using the syntax
  5812. @example
  5813. @var{name}[@var{subscript}]=@var{value}
  5814. @end example
  5815. @noindent
  5816. The @var{subscript}
  5817. is treated as an arithmetic expression that must evaluate to a number.
  5818. To explicitly declare an array, use
  5819. @example
  5820. declare -a @var{name}
  5821. @end example
  5822. @noindent
  5823. The syntax
  5824. @example
  5825. declare -a @var{name}[@var{subscript}]
  5826. @end example
  5827. @noindent
  5828. is also accepted; the @var{subscript} is ignored.
  5829. @noindent
  5830. Associative arrays are created using
  5831. @example
  5832. declare -A @var{name}.
  5833. @end example
  5834. Attributes may be
  5835. specified for an array variable using the @code{declare} and
  5836. @code{readonly} builtins. Each attribute applies to all members of
  5837. an array.
  5838. Arrays are assigned to using compound assignments of the form
  5839. @example
  5840. @var{name}=(@var{value1} @var{value2} @dots{} )
  5841. @end example
  5842. @noindent
  5843. where each
  5844. @var{value} is of the form @code{[@var{subscript}]=}@var{string}.
  5845. Indexed array assignments do not require anything but @var{string}.
  5846. When assigning to indexed arrays, if
  5847. the optional subscript is supplied, that index is assigned to;
  5848. otherwise the index of the element assigned is the last index assigned
  5849. to by the statement plus one. Indexing starts at zero.
  5850. When assigning to an associative array, the subscript is required.
  5851. This syntax is also accepted by the @code{declare}
  5852. builtin. Individual array elements may be assigned to using the
  5853. @code{@var{name}[@var{subscript}]=@var{value}} syntax introduced above.
  5854. When assigning to an indexed array, if @var{name}
  5855. is subscripted by a negative number, that number is
  5856. interpreted as relative to one greater than the maximum index of
  5857. @var{name}, so negative indices count back from the end of the
  5858. array, and an index of -1 references the last element.
  5859. Any element of an array may be referenced using
  5860. @code{$@{@var{name}[@var{subscript}]@}}.
  5861. The braces are required to avoid
  5862. conflicts with the shell's filename expansion operators. If the
  5863. @var{subscript} is @samp{@@} or @samp{*}, the word expands to all members
  5864. of the array @var{name}. These subscripts differ only when the word
  5865. appears within double quotes.
  5866. If the word is double-quoted,
  5867. @code{$@{@var{name}[*]@}} expands to a single word with
  5868. the value of each array member separated by the first character of the
  5869. @env{IFS} variable, and @code{$@{@var{name}[@@]@}} expands each element of
  5870. @var{name} to a separate word. When there are no array members,
  5871. @code{$@{@var{name}[@@]@}} expands to nothing.
  5872. If the double-quoted expansion occurs within a word, the expansion of
  5873. the first parameter is joined with the beginning part of the original
  5874. word, and the expansion of the last parameter is joined with the last
  5875. part of the original word.
  5876. This is analogous to the
  5877. expansion of the special parameters @samp{@@} and @samp{*}.
  5878. @code{$@{#@var{name}[@var{subscript}]@}} expands to the length of
  5879. @code{$@{@var{name}[@var{subscript}]@}}.
  5880. If @var{subscript} is @samp{@@} or
  5881. @samp{*}, the expansion is the number of elements in the array.
  5882. If the @var{subscript}
  5883. used to reference an element of an indexed array
  5884. evaluates to a number less than zero, it is
  5885. interpreted as relative to one greater than the maximum index of the array,
  5886. so negative indices count back from the end of the array,
  5887. and an index of -1 refers to the last element.
  5888. Referencing an array variable without a subscript is equivalent to
  5889. referencing with a subscript of 0.
  5890. Any reference to a variable using a valid subscript is legal, and
  5891. @code{bash} will create an array if necessary.
  5892. An array variable is considered set if a subscript has been assigned a
  5893. value. The null string is a valid value.
  5894. It is possible to obtain the keys (indices) of an array as well as the values.
  5895. $@{!@var{name}[@@]@} and $@{!@var{name}[*]@} expand to the indices
  5896. assigned in array variable @var{name}.
  5897. The treatment when in double quotes is similar to the expansion of the
  5898. special parameters @samp{@@} and @samp{*} within double quotes.
  5899. The @code{unset} builtin is used to destroy arrays.
  5900. @code{unset @var{name}[@var{subscript}]}
  5901. destroys the array element at index @var{subscript}.
  5902. Negative subscripts to indexed arrays are interpreted as described above.
  5903. Care must be taken to avoid unwanted side effects caused by filename
  5904. expansion.
  5905. @code{unset @var{name}}, where @var{name} is an array, removes the
  5906. entire array. A subscript of @samp{*} or @samp{@@} also removes the
  5907. entire array.
  5908. The @code{declare}, @code{local}, and @code{readonly}
  5909. builtins each accept a @option{-a} option to specify an indexed
  5910. array and a @option{-A} option to specify an associative array.
  5911. If both options are supplied, @option{-A} takes precedence.
  5912. The @code{read} builtin accepts a @option{-a}
  5913. option to assign a list of words read from the standard input
  5914. to an array, and can read values from the standard input into
  5915. individual array elements. The @code{set} and @code{declare}
  5916. builtins display array values in a way that allows them to be
  5917. reused as input.
  5918. @node The Directory Stack
  5919. @section The Directory Stack
  5920. @cindex directory stack
  5921. @menu
  5922. * Directory Stack Builtins:: Bash builtin commands to manipulate
  5923. the directory stack.
  5924. @end menu
  5925. The directory stack is a list of recently-visited directories. The
  5926. @code{pushd} builtin adds directories to the stack as it changes
  5927. the current directory, and the @code{popd} builtin removes specified
  5928. directories from the stack and changes the current directory to
  5929. the directory removed. The @code{dirs} builtin displays the contents
  5930. of the directory stack. The current directory is always the "top"
  5931. of the directory stack.
  5932. The contents of the directory stack are also visible
  5933. as the value of the @env{DIRSTACK} shell variable.
  5934. @node Directory Stack Builtins
  5935. @subsection Directory Stack Builtins
  5936. @table @code
  5937. @item dirs
  5938. @btindex dirs
  5939. @example
  5940. dirs [-clpv] [+@var{N} | -@var{N}]
  5941. @end example
  5942. Display the list of currently remembered directories. Directories
  5943. are added to the list with the @code{pushd} command; the
  5944. @code{popd} command removes directories from the list.
  5945. The current directory is always the first directory in the stack.
  5946. @table @code
  5947. @item -c
  5948. Clears the directory stack by deleting all of the elements.
  5949. @item -l
  5950. Produces a listing using full pathnames;
  5951. the default listing format uses a tilde to denote the home directory.
  5952. @item -p
  5953. Causes @code{dirs} to print the directory stack with one entry per
  5954. line.
  5955. @item -v
  5956. Causes @code{dirs} to print the directory stack with one entry per
  5957. line, prefixing each entry with its index in the stack.
  5958. @item +@var{N}
  5959. Displays the @var{N}th directory (counting from the left of the
  5960. list printed by @code{dirs} when invoked without options), starting
  5961. with zero.
  5962. @item -@var{N}
  5963. Displays the @var{N}th directory (counting from the right of the
  5964. list printed by @code{dirs} when invoked without options), starting
  5965. with zero.
  5966. @end table
  5967. @item popd
  5968. @btindex popd
  5969. @example
  5970. popd [-n] [+@var{N} | -@var{N}]
  5971. @end example
  5972. When no arguments are given, @code{popd}
  5973. removes the top directory from the stack and
  5974. performs a @code{cd} to the new top directory.
  5975. The elements are numbered from 0 starting at the first directory
  5976. listed with @code{dirs}; that is, @code{popd} is equivalent to @code{popd +0}.
  5977. @table @code
  5978. @item -n
  5979. Suppresses the normal change of directory when removing directories
  5980. from the stack, so that only the stack is manipulated.
  5981. @item +@var{N}
  5982. Removes the @var{N}th directory (counting from the left of the
  5983. list printed by @code{dirs}), starting with zero.
  5984. @item -@var{N}
  5985. Removes the @var{N}th directory (counting from the right of the
  5986. list printed by @code{dirs}), starting with zero.
  5987. @end table
  5988. @btindex pushd
  5989. @item pushd
  5990. @example
  5991. pushd [-n] [@var{+N} | @var{-N} | @var{dir}]
  5992. @end example
  5993. Save the current directory on the top of the directory stack
  5994. and then @code{cd} to @var{dir}.
  5995. With no arguments, @code{pushd} exchanges the top two directories
  5996. and makes the new top the current directory.
  5997. @table @code
  5998. @item -n
  5999. Suppresses the normal change of directory when rotating or
  6000. adding directories to the stack, so that only the stack is manipulated.
  6001. @item +@var{N}
  6002. Brings the @var{N}th directory (counting from the left of the
  6003. list printed by @code{dirs}, starting with zero) to the top of
  6004. the list by rotating the stack.
  6005. @item -@var{N}
  6006. Brings the @var{N}th directory (counting from the right of the
  6007. list printed by @code{dirs}, starting with zero) to the top of
  6008. the list by rotating the stack.
  6009. @item @var{dir}
  6010. Makes @var{dir} be the top of the stack, making
  6011. it the new current directory as if it had been supplied as an argument
  6012. to the @code{cd} builtin.
  6013. @end table
  6014. @end table
  6015. @node Controlling the Prompt
  6016. @section Controlling the Prompt
  6017. @cindex prompting
  6018. The value of the variable @env{PROMPT_COMMAND} is examined just before
  6019. Bash prints each primary prompt. If @env{PROMPT_COMMAND} is set and
  6020. has a non-null value, then the
  6021. value is executed just as if it had been typed on the command line.
  6022. In addition, the following table describes the special characters which
  6023. can appear in the prompt variables @env{PS1} to @env{PS4}:
  6024. @table @code
  6025. @item \a
  6026. A bell character.
  6027. @item \d
  6028. The date, in "Weekday Month Date" format (e.g., "Tue May 26").
  6029. @item \D@{@var{format}@}
  6030. The @var{format} is passed to @code{strftime}(3) and the result is inserted
  6031. into the prompt string; an empty @var{format} results in a locale-specific
  6032. time representation. The braces are required.
  6033. @item \e
  6034. An escape character.
  6035. @item \h
  6036. The hostname, up to the first `.'.
  6037. @item \H
  6038. The hostname.
  6039. @item \j
  6040. The number of jobs currently managed by the shell.
  6041. @item \l
  6042. The basename of the shell's terminal device name.
  6043. @item \n
  6044. A newline.
  6045. @item \r
  6046. A carriage return.
  6047. @item \s
  6048. The name of the shell, the basename of @code{$0} (the portion
  6049. following the final slash).
  6050. @item \t
  6051. The time, in 24-hour HH:MM:SS format.
  6052. @item \T
  6053. The time, in 12-hour HH:MM:SS format.
  6054. @item \@@
  6055. The time, in 12-hour am/pm format.
  6056. @item \A
  6057. The time, in 24-hour HH:MM format.
  6058. @item \u
  6059. The username of the current user.
  6060. @item \v
  6061. The version of Bash (e.g., 2.00)
  6062. @item \V
  6063. The release of Bash, version + patchlevel (e.g., 2.00.0)
  6064. @item \w
  6065. The current working directory, with @env{$HOME} abbreviated with a tilde
  6066. (uses the @env{$PROMPT_DIRTRIM} variable).
  6067. @item \W
  6068. The basename of @env{$PWD}, with @env{$HOME} abbreviated with a tilde.
  6069. @item \!
  6070. The history number of this command.
  6071. @item \#
  6072. The command number of this command.
  6073. @item \$
  6074. If the effective uid is 0, @code{#}, otherwise @code{$}.
  6075. @item \@var{nnn}
  6076. The character whose ASCII code is the octal value @var{nnn}.
  6077. @item \\
  6078. A backslash.
  6079. @item \[
  6080. Begin a sequence of non-printing characters. This could be used to
  6081. embed a terminal control sequence into the prompt.
  6082. @item \]
  6083. End a sequence of non-printing characters.
  6084. @end table
  6085. The command number and the history number are usually different:
  6086. the history number of a command is its position in the history
  6087. list, which may include commands restored from the history file
  6088. (@pxref{Bash History Facilities}), while the command number is
  6089. the position in the sequence of commands executed during the current
  6090. shell session.
  6091. After the string is decoded, it is expanded via
  6092. parameter expansion, command substitution, arithmetic
  6093. expansion, and quote removal, subject to the value of the
  6094. @code{promptvars} shell option (@pxref{Bash Builtins}).
  6095. @node The Restricted Shell
  6096. @section The Restricted Shell
  6097. @cindex restricted shell
  6098. If Bash is started with the name @code{rbash}, or the
  6099. @option{--restricted}
  6100. or
  6101. @option{-r}
  6102. option is supplied at invocation, the shell becomes restricted.
  6103. A restricted shell is used to
  6104. set up an environment more controlled than the standard shell.
  6105. A restricted shell behaves identically to @code{bash}
  6106. with the exception that the following are disallowed or not performed:
  6107. @itemize @bullet
  6108. @item
  6109. Changing directories with the @code{cd} builtin.
  6110. @item
  6111. Setting or unsetting the values of the @env{SHELL}, @env{PATH},
  6112. @env{ENV}, or @env{BASH_ENV} variables.
  6113. @item
  6114. Specifying command names containing slashes.
  6115. @item
  6116. Specifying a filename containing a slash as an argument to the @code{.}
  6117. builtin command.
  6118. @item
  6119. Specifying a filename containing a slash as an argument to the @option{-p}
  6120. option to the @code{hash} builtin command.
  6121. @item
  6122. Importing function definitions from the shell environment at startup.
  6123. @item
  6124. Parsing the value of @env{SHELLOPTS} from the shell environment at startup.
  6125. @item
  6126. Redirecting output using the @samp{>}, @samp{>|}, @samp{<>}, @samp{>&},
  6127. @samp{&>}, and @samp{>>} redirection operators.
  6128. @item
  6129. Using the @code{exec} builtin to replace the shell with another command.
  6130. @item
  6131. Adding or deleting builtin commands with the
  6132. @option{-f} and @option{-d} options to the @code{enable} builtin.
  6133. @item
  6134. Using the @code{enable} builtin command to enable disabled shell builtins.
  6135. @item
  6136. Specifying the @option{-p} option to the @code{command} builtin.
  6137. @item
  6138. Turning off restricted mode with @samp{set +r} or @samp{set +o restricted}.
  6139. @end itemize
  6140. These restrictions are enforced after any startup files are read.
  6141. When a command that is found to be a shell script is executed
  6142. (@pxref{Shell Scripts}), @code{rbash} turns off any restrictions in
  6143. the shell spawned to execute the script.
  6144. @node Bash POSIX Mode
  6145. @section Bash POSIX Mode
  6146. @cindex POSIX Mode
  6147. Starting Bash with the @option{--posix} command-line option or executing
  6148. @samp{set -o posix} while Bash is running will cause Bash to conform more
  6149. closely to the @sc{posix} standard by changing the behavior to
  6150. match that specified by @sc{posix} in areas where the Bash default differs.
  6151. When invoked as @code{sh}, Bash enters @sc{posix} mode after reading the
  6152. startup files.
  6153. The following list is what's changed when `@sc{posix} mode' is in effect:
  6154. @enumerate
  6155. @item
  6156. When a command in the hash table no longer exists, Bash will re-search
  6157. @env{$PATH} to find the new location. This is also available with
  6158. @samp{shopt -s checkhash}.
  6159. @item
  6160. The message printed by the job control code and builtins when a job
  6161. exits with a non-zero status is `Done(status)'.
  6162. @item
  6163. The message printed by the job control code and builtins when a job
  6164. is stopped is `Stopped(@var{signame})', where @var{signame} is, for
  6165. example, @code{SIGTSTP}.
  6166. @item
  6167. Alias expansion is always enabled, even in non-interactive shells.
  6168. @item
  6169. Reserved words appearing in a context where reserved words are recognized
  6170. do not undergo alias expansion.
  6171. @item
  6172. The @sc{posix} @env{PS1} and @env{PS2} expansions of @samp{!} to
  6173. the history number and @samp{!!} to @samp{!} are enabled,
  6174. and parameter expansion is performed on the values of @env{PS1} and
  6175. @env{PS2} regardless of the setting of the @code{promptvars} option.
  6176. @item
  6177. The @sc{posix} startup files are executed (@env{$ENV}) rather than
  6178. the normal Bash files.
  6179. @item
  6180. Tilde expansion is only performed on assignments preceding a command
  6181. name, rather than on all assignment statements on the line.
  6182. @item
  6183. The default history file is @file{~/.sh_history} (this is the
  6184. default value of @env{$HISTFILE}).
  6185. @item
  6186. Redirection operators do not perform filename expansion on the word
  6187. in the redirection unless the shell is interactive.
  6188. @item
  6189. Redirection operators do not perform word splitting on the word in the
  6190. redirection.
  6191. @item
  6192. Function names must be valid shell @code{name}s. That is, they may not
  6193. contain characters other than letters, digits, and underscores, and
  6194. may not start with a digit. Declaring a function with an invalid name
  6195. causes a fatal syntax error in non-interactive shells.
  6196. @item
  6197. Function names may not be the same as one of the @sc{posix} special
  6198. builtins.
  6199. @item
  6200. @sc{posix} special builtins are found before shell functions
  6201. during command lookup.
  6202. @item
  6203. When printing shell function definitions (e.g., by @code{type}), Bash does
  6204. not print the @code{function} keyword.
  6205. @item
  6206. Literal tildes that appear as the first character in elements of
  6207. the @env{PATH} variable are not expanded as described above
  6208. under @ref{Tilde Expansion}.
  6209. @item
  6210. The @code{time} reserved word may be used by itself as a command. When
  6211. used in this way, it displays timing statistics for the shell and its
  6212. completed children. The @env{TIMEFORMAT} variable controls the format
  6213. of the timing information.
  6214. @item
  6215. When parsing and expanding a $@{@dots{}@} expansion that appears within
  6216. double quotes, single quotes are no longer special and cannot be used to
  6217. quote a closing brace or other special character, unless the operator is
  6218. one of those defined to perform pattern removal. In this case, they do
  6219. not have to appear as matched pairs.
  6220. @item
  6221. The parser does not recognize @code{time} as a reserved word if the next
  6222. token begins with a @samp{-}.
  6223. @item
  6224. The @samp{!} character does not introduce history expansion within a
  6225. double-quoted string, even if the @code{histexpand} option is enabled.
  6226. @item
  6227. If a @sc{posix} special builtin returns an error status, a
  6228. non-interactive shell exits. The fatal errors are those listed in
  6229. the @sc{posix} standard, and include things like passing incorrect options,
  6230. redirection errors, variable assignment errors for assignments preceding
  6231. the command name, and so on.
  6232. @item
  6233. A non-interactive shell exits with an error status if a variable
  6234. assignment error occurs when no command name follows the assignment
  6235. statements.
  6236. A variable assignment error occurs, for example, when trying to assign
  6237. a value to a readonly variable.
  6238. @item
  6239. A non-interactive shell exits with an error status if a variable
  6240. assignment error occurs in an assignment statement preceding a special
  6241. builtin, but not with any other simple command.
  6242. @item
  6243. A non-interactive shell exits with an error status if the iteration
  6244. variable in a @code{for} statement or the selection variable in a
  6245. @code{select} statement is a readonly variable.
  6246. @item
  6247. Non-interactive shells exit if @var{filename} in @code{.} @var{filename}
  6248. is not found.
  6249. @item
  6250. Non-interactive shells exit if a syntax error in an arithmetic expansion
  6251. results in an invalid expression.
  6252. @item
  6253. Non-interactive shells exit if a parameter expansion error occurs.
  6254. @item
  6255. Non-interactive shells exit if there is a syntax error in a script read
  6256. with the @code{.} or @code{source} builtins, or in a string processed by
  6257. the @code{eval} builtin.
  6258. @item
  6259. Process substitution is not available.
  6260. @item
  6261. While variable indirection is available, it may not be applied to the
  6262. @samp{#} and @samp{?} special parameters.
  6263. @item
  6264. When expanding the @samp{*} special parameter in a pattern context where the
  6265. expansion is double-quoted does not treat the @code{$*} as if it were
  6266. double-quoted.
  6267. @item
  6268. Assignment statements preceding @sc{posix} special builtins
  6269. persist in the shell environment after the builtin completes.
  6270. @item
  6271. Assignment statements preceding shell function calls persist in the
  6272. shell environment after the function returns, as if a @sc{posix}
  6273. special builtin command had been executed.
  6274. @item
  6275. The @code{command} builtin does not prevent builtins that take assignment
  6276. statements as arguments from expanding them as assignment statements;
  6277. when not in @sc{posix} mode, assignment builtins lose their assignment
  6278. statement expansion properties when preceded by @code{command}.
  6279. @item
  6280. The @code{bg} builtin uses the required format to describe each job placed
  6281. in the background, which does not include an indication of whether the job
  6282. is the current or previous job.
  6283. @item
  6284. The output of @samp{kill -l} prints all the signal names on a single line,
  6285. separated by spaces, without the @samp{SIG} prefix.
  6286. @item
  6287. The @code{kill} builtin does not accept signal names with a @samp{SIG}
  6288. prefix.
  6289. @item
  6290. The @code{export} and @code{readonly} builtin commands display their
  6291. output in the format required by @sc{posix}.
  6292. @item
  6293. The @code{trap} builtin displays signal names without the leading
  6294. @code{SIG}.
  6295. @item
  6296. The @code{trap} builtin doesn't check the first argument for a possible
  6297. signal specification and revert the signal handling to the original
  6298. disposition if it is, unless that argument consists solely of digits and
  6299. is a valid signal number. If users want to reset the handler for a given
  6300. signal to the original disposition, they should use @samp{-} as the
  6301. first argument.
  6302. @item
  6303. The @code{.} and @code{source} builtins do not search the current directory
  6304. for the filename argument if it is not found by searching @env{PATH}.
  6305. @item
  6306. Enabling @sc{posix} mode has the effect of setting the
  6307. @code{inherit_errexit} option, so
  6308. subshells spawned to execute command substitutions inherit the value of
  6309. the @option{-e} option from the parent shell.
  6310. When the @code{inherit_errexit} option is not enabled,
  6311. Bash clears the @option{-e} option in such subshells.
  6312. @item
  6313. When the @code{alias} builtin displays alias definitions, it does not
  6314. display them with a leading @samp{alias } unless the @option{-p} option
  6315. is supplied.
  6316. @item
  6317. When the @code{set} builtin is invoked without options, it does not display
  6318. shell function names and definitions.
  6319. @item
  6320. When the @code{set} builtin is invoked without options, it displays
  6321. variable values without quotes, unless they contain shell metacharacters,
  6322. even if the result contains nonprinting characters.
  6323. @item
  6324. When the @code{cd} builtin is invoked in @var{logical} mode, and the pathname
  6325. constructed from @code{$PWD} and the directory name supplied as an argument
  6326. does not refer to an existing directory, @code{cd} will fail instead of
  6327. falling back to @var{physical} mode.
  6328. @item
  6329. The @code{pwd} builtin verifies that the value it prints is the same as the
  6330. current directory, even if it is not asked to check the file system with the
  6331. @option{-P} option.
  6332. @item
  6333. When listing the history, the @code{fc} builtin does not include an
  6334. indication of whether or not a history entry has been modified.
  6335. @item
  6336. The default editor used by @code{fc} is @code{ed}.
  6337. @item
  6338. The @code{type} and @code{command} builtins will not report a non-executable
  6339. file as having been found, though the shell will attempt to execute such a
  6340. file if it is the only so-named file found in @code{$PATH}.
  6341. @item
  6342. The @code{vi} editing mode will invoke the @code{vi} editor directly when
  6343. the @samp{v} command is run, instead of checking @code{$VISUAL} and
  6344. @code{$EDITOR}.
  6345. @item
  6346. When the @code{xpg_echo} option is enabled, Bash does not attempt to interpret
  6347. any arguments to @code{echo} as options. Each argument is displayed, after
  6348. escape characters are converted.
  6349. @item
  6350. The @code{ulimit} builtin uses a block size of 512 bytes for the @option{-c}
  6351. and @option{-f} options.
  6352. @item
  6353. The arrival of @code{SIGCHLD} when a trap is set on @code{SIGCHLD} does
  6354. not interrupt the @code{wait} builtin and cause it to return immediately.
  6355. The trap command is run once for each child that exits.
  6356. @item
  6357. The @code{read} builtin may be interrupted by a signal for which a trap
  6358. has been set.
  6359. If Bash receives a trapped signal while executing @code{read}, the trap
  6360. handler executes and @code{read} returns an exit status greater than 128.
  6361. @item
  6362. Bash removes an exited background process's status from the list of such
  6363. statuses after the @code{wait} builtin is used to obtain it.
  6364. @end enumerate
  6365. There is other @sc{posix} behavior that Bash does not implement by
  6366. default even when in @sc{posix} mode.
  6367. Specifically:
  6368. @enumerate
  6369. @item
  6370. The @code{fc} builtin checks @code{$EDITOR} as a program to edit history
  6371. entries if @code{FCEDIT} is unset, rather than defaulting directly to
  6372. @code{ed}. @code{fc} uses @code{ed} if @code{EDITOR} is unset.
  6373. @item
  6374. As noted above, Bash requires the @code{xpg_echo} option to be enabled for
  6375. the @code{echo} builtin to be fully conformant.
  6376. @end enumerate
  6377. Bash can be configured to be @sc{posix}-conformant by default, by specifying
  6378. the @option{--enable-strict-posix-default} to @code{configure} when building
  6379. (@pxref{Optional Features}).
  6380. @node Job Control
  6381. @chapter Job Control
  6382. This chapter discusses what job control is, how it works, and how
  6383. Bash allows you to access its facilities.
  6384. @menu
  6385. * Job Control Basics:: How job control works.
  6386. * Job Control Builtins:: Bash builtin commands used to interact
  6387. with job control.
  6388. * Job Control Variables:: Variables Bash uses to customize job
  6389. control.
  6390. @end menu
  6391. @node Job Control Basics
  6392. @section Job Control Basics
  6393. @cindex job control
  6394. @cindex foreground
  6395. @cindex background
  6396. @cindex suspending jobs
  6397. Job control
  6398. refers to the ability to selectively stop (suspend)
  6399. the execution of processes and continue (resume)
  6400. their execution at a later point. A user typically employs
  6401. this facility via an interactive interface supplied jointly
  6402. by the operating system kernel's terminal driver and Bash.
  6403. The shell associates a @var{job} with each pipeline. It keeps a
  6404. table of currently executing jobs, which may be listed with the
  6405. @code{jobs} command. When Bash starts a job
  6406. asynchronously, it prints a line that looks
  6407. like:
  6408. @example
  6409. [1] 25647
  6410. @end example
  6411. @noindent
  6412. indicating that this job is job number 1 and that the process @sc{id}
  6413. of the last process in the pipeline associated with this job is
  6414. 25647. All of the processes in a single pipeline are members of
  6415. the same job. Bash uses the @var{job} abstraction as the
  6416. basis for job control.
  6417. To facilitate the implementation of the user interface to job
  6418. control, the operating system maintains the notion of a current terminal
  6419. process group @sc{id}. Members of this process group (processes whose
  6420. process group @sc{id} is equal to the current terminal process group
  6421. @sc{id}) receive keyboard-generated signals such as @code{SIGINT}.
  6422. These processes are said to be in the foreground. Background
  6423. processes are those whose process group @sc{id} differs from the
  6424. terminal's; such processes are immune to keyboard-generated
  6425. signals. Only foreground processes are allowed to read from or, if
  6426. the user so specifies with @code{stty tostop}, write to the terminal.
  6427. Background processes which attempt to
  6428. read from (write to when @code{stty tostop} is in effect) the
  6429. terminal are sent a @code{SIGTTIN} (@code{SIGTTOU})
  6430. signal by the kernel's terminal driver,
  6431. which, unless caught, suspends the process.
  6432. If the operating system on which Bash is running supports
  6433. job control, Bash contains facilities to use it. Typing the
  6434. @var{suspend} character (typically @samp{^Z}, Control-Z) while a
  6435. process is running causes that process to be stopped and returns
  6436. control to Bash. Typing the @var{delayed suspend} character
  6437. (typically @samp{^Y}, Control-Y) causes the process to be stopped
  6438. when it attempts to read input from the terminal, and control to
  6439. be returned to Bash. The user then manipulates the state of
  6440. this job, using the @code{bg} command to continue it in the
  6441. background, the @code{fg} command to continue it in the
  6442. foreground, or the @code{kill} command to kill it. A @samp{^Z}
  6443. takes effect immediately, and has the additional side effect of
  6444. causing pending output and typeahead to be discarded.
  6445. There are a number of ways to refer to a job in the shell. The
  6446. character @samp{%} introduces a job specification (@var{jobspec}).
  6447. Job number @code{n} may be referred to as @samp{%n}.
  6448. The symbols @samp{%%} and @samp{%+} refer to the shell's notion of the
  6449. current job, which is the last job stopped while it was in the foreground
  6450. or started in the background.
  6451. A single @samp{%} (with no accompanying job specification) also refers
  6452. to the current job.
  6453. The previous job may be referenced using @samp{%-}.
  6454. If there is only a single job, @samp{%+} and @samp{%-} can both be used
  6455. to refer to that job.
  6456. In output pertaining to jobs (e.g., the output of the @code{jobs}
  6457. command), the current job is always flagged with a @samp{+}, and the
  6458. previous job with a @samp{-}.
  6459. A job may also be referred to
  6460. using a prefix of the name used to start it, or using a substring
  6461. that appears in its command line. For example, @samp{%ce} refers
  6462. to a stopped @code{ce} job. Using @samp{%?ce}, on the
  6463. other hand, refers to any job containing the string @samp{ce} in
  6464. its command line. If the prefix or substring matches more than one job,
  6465. Bash reports an error.
  6466. Simply naming a job can be used to bring it into the foreground:
  6467. @samp{%1} is a synonym for @samp{fg %1}, bringing job 1 from the
  6468. background into the foreground. Similarly, @samp{%1 &} resumes
  6469. job 1 in the background, equivalent to @samp{bg %1}
  6470. The shell learns immediately whenever a job changes state.
  6471. Normally, Bash waits until it is about to print a prompt
  6472. before reporting changes in a job's status so as to not interrupt
  6473. any other output.
  6474. If the @option{-b} option to the @code{set} builtin is enabled,
  6475. Bash reports such changes immediately (@pxref{The Set Builtin}).
  6476. Any trap on @code{SIGCHLD} is executed for each child process
  6477. that exits.
  6478. If an attempt to exit Bash is made while jobs are stopped, (or running, if
  6479. the @code{checkjobs} option is enabled -- see @ref{The Shopt Builtin}), the
  6480. shell prints a warning message, and if the @code{checkjobs} option is
  6481. enabled, lists the jobs and their statuses.
  6482. The @code{jobs} command may then be used to inspect their status.
  6483. If a second attempt to exit is made without an intervening command,
  6484. Bash does not print another warning, and any stopped jobs are terminated.
  6485. @node Job Control Builtins
  6486. @section Job Control Builtins
  6487. @table @code
  6488. @item bg
  6489. @btindex bg
  6490. @example
  6491. bg [@var{jobspec} @dots{}]
  6492. @end example
  6493. Resume each suspended job @var{jobspec} in the background, as if it
  6494. had been started with @samp{&}.
  6495. If @var{jobspec} is not supplied, the current job is used.
  6496. The return status is zero unless it is run when job control is not
  6497. enabled, or, when run with job control enabled, any
  6498. @var{jobspec} was not found or specifies a job
  6499. that was started without job control.
  6500. @item fg
  6501. @btindex fg
  6502. @example
  6503. fg [@var{jobspec}]
  6504. @end example
  6505. Resume the job @var{jobspec} in the foreground and make it the current job.
  6506. If @var{jobspec} is not supplied, the current job is used.
  6507. The return status is that of the command placed into the foreground,
  6508. or non-zero if run when job control is disabled or, when run with
  6509. job control enabled, @var{jobspec} does not specify a valid job or
  6510. @var{jobspec} specifies a job that was started without job control.
  6511. @item jobs
  6512. @btindex jobs
  6513. @example
  6514. jobs [-lnprs] [@var{jobspec}]
  6515. jobs -x @var{command} [@var{arguments}]
  6516. @end example
  6517. The first form lists the active jobs. The options have the
  6518. following meanings:
  6519. @table @code
  6520. @item -l
  6521. List process @sc{id}s in addition to the normal information.
  6522. @item -n
  6523. Display information only about jobs that have changed status since
  6524. the user was last notified of their status.
  6525. @item -p
  6526. List only the process @sc{id} of the job's process group leader.
  6527. @item -r
  6528. Display only running jobs.
  6529. @item -s
  6530. Display only stopped jobs.
  6531. @end table
  6532. If @var{jobspec} is given,
  6533. output is restricted to information about that job.
  6534. If @var{jobspec} is not supplied, the status of all jobs is
  6535. listed.
  6536. If the @option{-x} option is supplied, @code{jobs} replaces any
  6537. @var{jobspec} found in @var{command} or @var{arguments} with the
  6538. corresponding process group @sc{id}, and executes @var{command},
  6539. passing it @var{argument}s, returning its exit status.
  6540. @item kill
  6541. @btindex kill
  6542. @example
  6543. kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec} or @var{pid}
  6544. kill -l|-L [@var{exit_status}]
  6545. @end example
  6546. Send a signal specified by @var{sigspec} or @var{signum} to the process
  6547. named by job specification @var{jobspec} or process @sc{id} @var{pid}.
  6548. @var{sigspec} is either a case-insensitive signal name such as
  6549. @code{SIGINT} (with or without the @code{SIG} prefix)
  6550. or a signal number; @var{signum} is a signal number.
  6551. If @var{sigspec} and @var{signum} are not present, @code{SIGTERM} is used.
  6552. The @option{-l} option lists the signal names.
  6553. If any arguments are supplied when @option{-l} is given, the names of the
  6554. signals corresponding to the arguments are listed, and the return status
  6555. is zero.
  6556. @var{exit_status} is a number specifying a signal number or the exit
  6557. status of a process terminated by a signal.
  6558. The @option{-L} option is equivalent to @option{-l}.
  6559. The return status is zero if at least one signal was successfully sent,
  6560. or non-zero if an error occurs or an invalid option is encountered.
  6561. @item wait
  6562. @btindex wait
  6563. @example
  6564. wait [-n] [@var{jobspec} or @var{pid} @dots{}]
  6565. @end example
  6566. Wait until the child process specified by each process @sc{id} @var{pid}
  6567. or job specification @var{jobspec} exits and return the exit status of the
  6568. last command waited for.
  6569. If a job spec is given, all processes in the job are waited for.
  6570. If no arguments are given, all currently active child processes are
  6571. waited for, and the return status is zero.
  6572. If the @option{-n} option is supplied, @code{wait} waits for any job to
  6573. terminate and returns its exit status.
  6574. If neither @var{jobspec} nor @var{pid} specifies an active child process
  6575. of the shell, the return status is 127.
  6576. @item disown
  6577. @btindex disown
  6578. @example
  6579. disown [-ar] [-h] [@var{jobspec} @dots{} | @var{pid} @dots{} ]
  6580. @end example
  6581. Without options, remove each @var{jobspec} from the table of
  6582. active jobs.
  6583. If the @option{-h} option is given, the job is not removed from the table,
  6584. but is marked so that @code{SIGHUP} is not sent to the job if the shell
  6585. receives a @code{SIGHUP}.
  6586. If @var{jobspec} is not present, and neither the @option{-a} nor the
  6587. @option{-r} option is supplied, the current job is used.
  6588. If no @var{jobspec} is supplied, the @option{-a} option means to remove or
  6589. mark all jobs; the @option{-r} option without a @var{jobspec}
  6590. argument restricts operation to running jobs.
  6591. @item suspend
  6592. @btindex suspend
  6593. @example
  6594. suspend [-f]
  6595. @end example
  6596. Suspend the execution of this shell until it receives a
  6597. @code{SIGCONT} signal.
  6598. A login shell cannot be suspended; the @option{-f}
  6599. option can be used to override this and force the suspension.
  6600. @end table
  6601. When job control is not active, the @code{kill} and @code{wait}
  6602. builtins do not accept @var{jobspec} arguments. They must be
  6603. supplied process @sc{id}s.
  6604. @node Job Control Variables
  6605. @section Job Control Variables
  6606. @vtable @code
  6607. @item auto_resume
  6608. This variable controls how the shell interacts with the user and
  6609. job control. If this variable exists then single word simple
  6610. commands without redirections are treated as candidates for resumption
  6611. of an existing job. There is no ambiguity allowed; if there is
  6612. more than one job beginning with the string typed, then
  6613. the most recently accessed job will be selected.
  6614. The name of a stopped job, in this context, is the command line
  6615. used to start it. If this variable is set to the value @samp{exact},
  6616. the string supplied must match the name of a stopped job exactly;
  6617. if set to @samp{substring},
  6618. the string supplied needs to match a substring of the name of a
  6619. stopped job. The @samp{substring} value provides functionality
  6620. analogous to the @samp{%?} job @sc{id} (@pxref{Job Control Basics}).
  6621. If set to any other value, the supplied string must
  6622. be a prefix of a stopped job's name; this provides functionality
  6623. analogous to the @samp{%} job @sc{id}.
  6624. @end vtable
  6625. @set readline-appendix
  6626. @set history-appendix
  6627. @cindex Readline, how to use
  6628. @include rluser.texi
  6629. @cindex History, how to use
  6630. @include hsuser.texi
  6631. @clear readline-appendix
  6632. @clear history-appendix
  6633. @node Installing Bash
  6634. @chapter Installing Bash
  6635. This chapter provides basic instructions for installing Bash on
  6636. the various supported platforms. The distribution supports the
  6637. @sc{gnu} operating systems, nearly every version of Unix, and several
  6638. non-Unix systems such as BeOS and Interix.
  6639. Other independent ports exist for
  6640. @sc{ms-dos}, @sc{os/2}, and Windows platforms.
  6641. @menu
  6642. * Basic Installation:: Installation instructions.
  6643. * Compilers and Options:: How to set special options for various
  6644. systems.
  6645. * Compiling For Multiple Architectures:: How to compile Bash for more
  6646. than one kind of system from
  6647. the same source tree.
  6648. * Installation Names:: How to set the various paths used by the installation.
  6649. * Specifying the System Type:: How to configure Bash for a particular system.
  6650. * Sharing Defaults:: How to share default configuration values among GNU
  6651. programs.
  6652. * Operation Controls:: Options recognized by the configuration program.
  6653. * Optional Features:: How to enable and disable optional features when
  6654. building Bash.
  6655. @end menu
  6656. @node Basic Installation
  6657. @section Basic Installation
  6658. @cindex installation
  6659. @cindex configuration
  6660. @cindex Bash installation
  6661. @cindex Bash configuration
  6662. These are installation instructions for Bash.
  6663. The simplest way to compile Bash is:
  6664. @enumerate
  6665. @item
  6666. @code{cd} to the directory containing the source code and type
  6667. @samp{./configure} to configure Bash for your system. If you're
  6668. using @code{csh} on an old version of System V, you might need to
  6669. type @samp{sh ./configure} instead to prevent @code{csh} from trying
  6670. to execute @code{configure} itself.
  6671. Running @code{configure} takes some time.
  6672. While running, it prints messages telling which features it is
  6673. checking for.
  6674. @item
  6675. Type @samp{make} to compile Bash and build the @code{bashbug} bug
  6676. reporting script.
  6677. @item
  6678. Optionally, type @samp{make tests} to run the Bash test suite.
  6679. @item
  6680. Type @samp{make install} to install @code{bash} and @code{bashbug}.
  6681. This will also install the manual pages and Info file.
  6682. @end enumerate
  6683. The @code{configure} shell script attempts to guess correct
  6684. values for various system-dependent variables used during
  6685. compilation. It uses those values to create a @file{Makefile} in
  6686. each directory of the package (the top directory, the
  6687. @file{builtins}, @file{doc}, and @file{support} directories,
  6688. each directory under @file{lib}, and several others). It also creates a
  6689. @file{config.h} file containing system-dependent definitions.
  6690. Finally, it creates a shell script named @code{config.status} that you
  6691. can run in the future to recreate the current configuration, a
  6692. file @file{config.cache} that saves the results of its tests to
  6693. speed up reconfiguring, and a file @file{config.log} containing
  6694. compiler output (useful mainly for debugging @code{configure}).
  6695. If at some point
  6696. @file{config.cache} contains results you don't want to keep, you
  6697. may remove or edit it.
  6698. To find out more about the options and arguments that the
  6699. @code{configure} script understands, type
  6700. @example
  6701. bash-2.04$ ./configure --help
  6702. @end example
  6703. @noindent
  6704. at the Bash prompt in your Bash source directory.
  6705. If you need to do unusual things to compile Bash, please
  6706. try to figure out how @code{configure} could check whether or not
  6707. to do them, and mail diffs or instructions to
  6708. @email{bash-maintainers@@gnu.org} so they can be
  6709. considered for the next release.
  6710. The file @file{configure.ac} is used to create @code{configure}
  6711. by a program called Autoconf. You only need
  6712. @file{configure.ac} if you want to change it or regenerate
  6713. @code{configure} using a newer version of Autoconf. If
  6714. you do this, make sure you are using Autoconf version 2.50 or
  6715. newer.
  6716. You can remove the program binaries and object files from the
  6717. source code directory by typing @samp{make clean}. To also remove the
  6718. files that @code{configure} created (so you can compile Bash for
  6719. a different kind of computer), type @samp{make distclean}.
  6720. @node Compilers and Options
  6721. @section Compilers and Options
  6722. Some systems require unusual options for compilation or linking
  6723. that the @code{configure} script does not know about. You can
  6724. give @code{configure} initial values for variables by setting
  6725. them in the environment. Using a Bourne-compatible shell, you
  6726. can do that on the command line like this:
  6727. @example
  6728. CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
  6729. @end example
  6730. On systems that have the @code{env} program, you can do it like this:
  6731. @example
  6732. env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
  6733. @end example
  6734. The configuration process uses GCC to build Bash if it
  6735. is available.
  6736. @node Compiling For Multiple Architectures
  6737. @section Compiling For Multiple Architectures
  6738. You can compile Bash for more than one kind of computer at the
  6739. same time, by placing the object files for each architecture in their
  6740. own directory. To do this, you must use a version of @code{make} that
  6741. supports the @code{VPATH} variable, such as GNU @code{make}.
  6742. @code{cd} to the
  6743. directory where you want the object files and executables to go and run
  6744. the @code{configure} script from the source directory. You may need to
  6745. supply the @option{--srcdir=PATH} argument to tell @code{configure} where the
  6746. source files are. @code{configure} automatically checks for the
  6747. source code in the directory that @code{configure} is in and in `..'.
  6748. If you have to use a @code{make} that does not supports the @code{VPATH}
  6749. variable, you can compile Bash for one architecture at a
  6750. time in the source code directory. After you have installed
  6751. Bash for one architecture, use @samp{make distclean} before
  6752. reconfiguring for another architecture.
  6753. Alternatively, if your system supports symbolic links, you can use the
  6754. @file{support/mkclone} script to create a build tree which has
  6755. symbolic links back to each file in the source directory. Here's an
  6756. example that creates a build directory in the current directory from a
  6757. source directory @file{/usr/gnu/src/bash-2.0}:
  6758. @example
  6759. bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
  6760. @end example
  6761. @noindent
  6762. The @code{mkclone} script requires Bash, so you must have already built
  6763. Bash for at least one architecture before you can create build
  6764. directories for other architectures.
  6765. @node Installation Names
  6766. @section Installation Names
  6767. By default, @samp{make install} will install into
  6768. @file{/usr/local/bin}, @file{/usr/local/man}, etc. You can
  6769. specify an installation prefix other than @file{/usr/local} by
  6770. giving @code{configure} the option @option{--prefix=@var{PATH}},
  6771. or by specifying a value for the @code{DESTDIR} @samp{make}
  6772. variable when running @samp{make install}.
  6773. You can specify separate installation prefixes for
  6774. architecture-specific files and architecture-independent files.
  6775. If you give @code{configure} the option
  6776. @option{--exec-prefix=@var{PATH}}, @samp{make install} will use
  6777. @var{PATH} as the prefix for installing programs and libraries.
  6778. Documentation and other data files will still use the regular prefix.
  6779. @node Specifying the System Type
  6780. @section Specifying the System Type
  6781. There may be some features @code{configure} can not figure out
  6782. automatically, but need to determine by the type of host Bash
  6783. will run on. Usually @code{configure} can figure that
  6784. out, but if it prints a message saying it can not guess the host
  6785. type, give it the @option{--host=TYPE} option. @samp{TYPE} can
  6786. either be a short name for the system type, such as @samp{sun4},
  6787. or a canonical name with three fields: @samp{CPU-COMPANY-SYSTEM}
  6788. (e.g., @samp{i386-unknown-freebsd4.2}).
  6789. See the file @file{support/config.sub} for the possible
  6790. values of each field.
  6791. @node Sharing Defaults
  6792. @section Sharing Defaults
  6793. If you want to set default values for @code{configure} scripts to
  6794. share, you can create a site shell script called
  6795. @code{config.site} that gives default values for variables like
  6796. @code{CC}, @code{cache_file}, and @code{prefix}. @code{configure}
  6797. looks for @file{PREFIX/share/config.site} if it exists, then
  6798. @file{PREFIX/etc/config.site} if it exists. Or, you can set the
  6799. @code{CONFIG_SITE} environment variable to the location of the site
  6800. script. A warning: the Bash @code{configure} looks for a site script,
  6801. but not all @code{configure} scripts do.
  6802. @node Operation Controls
  6803. @section Operation Controls
  6804. @code{configure} recognizes the following options to control how it
  6805. operates.
  6806. @table @code
  6807. @item --cache-file=@var{file}
  6808. Use and save the results of the tests in
  6809. @var{file} instead of @file{./config.cache}. Set @var{file} to
  6810. @file{/dev/null} to disable caching, for debugging
  6811. @code{configure}.
  6812. @item --help
  6813. Print a summary of the options to @code{configure}, and exit.
  6814. @item --quiet
  6815. @itemx --silent
  6816. @itemx -q
  6817. Do not print messages saying which checks are being made.
  6818. @item --srcdir=@var{dir}
  6819. Look for the Bash source code in directory @var{dir}. Usually
  6820. @code{configure} can determine that directory automatically.
  6821. @item --version
  6822. Print the version of Autoconf used to generate the @code{configure}
  6823. script, and exit.
  6824. @end table
  6825. @code{configure} also accepts some other, not widely used, boilerplate
  6826. options. @samp{configure --help} prints the complete list.
  6827. @node Optional Features
  6828. @section Optional Features
  6829. The Bash @code{configure} has a number of @option{--enable-@var{feature}}
  6830. options, where @var{feature} indicates an optional part of Bash.
  6831. There are also several @option{--with-@var{package}} options,
  6832. where @var{package} is something like @samp{bash-malloc} or @samp{purify}.
  6833. To turn off the default use of a package, use
  6834. @option{--without-@var{package}}. To configure Bash without a feature
  6835. that is enabled by default, use @option{--disable-@var{feature}}.
  6836. Here is a complete list of the @option{--enable-} and
  6837. @option{--with-} options that the Bash @code{configure} recognizes.
  6838. @table @code
  6839. @item --with-afs
  6840. Define if you are using the Andrew File System from Transarc.
  6841. @item --with-bash-malloc
  6842. Use the Bash version of
  6843. @code{malloc} in the directory @file{lib/malloc}. This is not the same
  6844. @code{malloc} that appears in @sc{gnu} libc, but an older version
  6845. originally derived from the 4.2 @sc{bsd} @code{malloc}. This @code{malloc}
  6846. is very fast, but wastes some space on each allocation.
  6847. This option is enabled by default.
  6848. The @file{NOTES} file contains a list of systems for
  6849. which this should be turned off, and @code{configure} disables this
  6850. option automatically for a number of systems.
  6851. @item --with-curses
  6852. Use the curses library instead of the termcap library. This should
  6853. be supplied if your system has an inadequate or incomplete termcap
  6854. database.
  6855. @item --with-gnu-malloc
  6856. A synonym for @code{--with-bash-malloc}.
  6857. @item --with-installed-readline[=@var{PREFIX}]
  6858. Define this to make Bash link with a locally-installed version of Readline
  6859. rather than the version in @file{lib/readline}. This works only with
  6860. Readline 5.0 and later versions. If @var{PREFIX} is @code{yes} or not
  6861. supplied, @code{configure} uses the values of the make variables
  6862. @code{includedir} and @code{libdir}, which are subdirectories of @code{prefix}
  6863. by default, to find the installed version of Readline if it is not in
  6864. the standard system include and library directories.
  6865. If @var{PREFIX} is @code{no}, Bash links with the version in
  6866. @file{lib/readline}.
  6867. If @var{PREFIX} is set to any other value, @code{configure} treats it as
  6868. a directory pathname and looks for
  6869. the installed version of Readline in subdirectories of that directory
  6870. (include files in @var{PREFIX}/@code{include} and the library in
  6871. @var{PREFIX}/@code{lib}).
  6872. @item --with-purify
  6873. Define this to use the Purify memory allocation checker from Rational
  6874. Software.
  6875. @item --enable-minimal-config
  6876. This produces a shell with minimal features, close to the historical
  6877. Bourne shell.
  6878. @end table
  6879. There are several @option{--enable-} options that alter how Bash is
  6880. compiled and linked, rather than changing run-time features.
  6881. @table @code
  6882. @item --enable-largefile
  6883. Enable support for @uref{http://www.sas.com/standards/large_file/x_open.20Mar96.html,
  6884. large files} if the operating system requires special compiler options
  6885. to build programs which can access large files. This is enabled by
  6886. default, if the operating system provides large file support.
  6887. @item --enable-profiling
  6888. This builds a Bash binary that produces profiling information to be
  6889. processed by @code{gprof} each time it is executed.
  6890. @item --enable-static-link
  6891. This causes Bash to be linked statically, if @code{gcc} is being used.
  6892. This could be used to build a version to use as root's shell.
  6893. @end table
  6894. The @samp{minimal-config} option can be used to disable all of
  6895. the following options, but it is processed first, so individual
  6896. options may be enabled using @samp{enable-@var{feature}}.
  6897. All of the following options except for @samp{disabled-builtins},
  6898. @samp{direxpand-default}, and
  6899. @samp{xpg-echo-default} are
  6900. enabled by default, unless the operating system does not provide the
  6901. necessary support.
  6902. @table @code
  6903. @item --enable-alias
  6904. Allow alias expansion and include the @code{alias} and @code{unalias}
  6905. builtins (@pxref{Aliases}).
  6906. @item --enable-arith-for-command
  6907. Include support for the alternate form of the @code{for} command
  6908. that behaves like the C language @code{for} statement
  6909. (@pxref{Looping Constructs}).
  6910. @item --enable-array-variables
  6911. Include support for one-dimensional array shell variables
  6912. (@pxref{Arrays}).
  6913. @item --enable-bang-history
  6914. Include support for @code{csh}-like history substitution
  6915. (@pxref{History Interaction}).
  6916. @item --enable-brace-expansion
  6917. Include @code{csh}-like brace expansion
  6918. ( @code{b@{a,b@}c} @expansion{} @code{bac bbc} ).
  6919. See @ref{Brace Expansion}, for a complete description.
  6920. @item --enable-casemod-attributes
  6921. Include support for case-modifying attributes in the @code{declare} builtin
  6922. and assignment statements. Variables with the @var{uppercase} attribute,
  6923. for example, will have their values converted to uppercase upon assignment.
  6924. @item --enable-casemod-expansion
  6925. Include support for case-modifying word expansions.
  6926. @item --enable-command-timing
  6927. Include support for recognizing @code{time} as a reserved word and for
  6928. displaying timing statistics for the pipeline following @code{time}
  6929. (@pxref{Pipelines}).
  6930. This allows pipelines as well as shell builtins and functions to be timed.
  6931. @item --enable-cond-command
  6932. Include support for the @code{[[} conditional command.
  6933. (@pxref{Conditional Constructs}).
  6934. @item --enable-cond-regexp
  6935. Include support for matching @sc{posix} regular expressions using the
  6936. @samp{=~} binary operator in the @code{[[} conditional command.
  6937. (@pxref{Conditional Constructs}).
  6938. @item --enable-coprocesses
  6939. Include support for coprocesses and the @code{coproc} reserved word
  6940. (@pxref{Pipelines}).
  6941. @item --enable-debugger
  6942. Include support for the bash debugger (distributed separately).
  6943. @item --enable-direxpand-default
  6944. Cause the @code{direxpand} shell option (@pxref{The Shopt Builtin})
  6945. to be enabled by default when the shell starts.
  6946. It is normally disabled by default.
  6947. @item --enable-directory-stack
  6948. Include support for a @code{csh}-like directory stack and the
  6949. @code{pushd}, @code{popd}, and @code{dirs} builtins
  6950. (@pxref{The Directory Stack}).
  6951. @item --enable-disabled-builtins
  6952. Allow builtin commands to be invoked via @samp{builtin xxx}
  6953. even after @code{xxx} has been disabled using @samp{enable -n xxx}.
  6954. See @ref{Bash Builtins}, for details of the @code{builtin} and
  6955. @code{enable} builtin commands.
  6956. @item --enable-dparen-arithmetic
  6957. Include support for the @code{((@dots{}))} command
  6958. (@pxref{Conditional Constructs}).
  6959. @item --enable-extended-glob
  6960. Include support for the extended pattern matching features described
  6961. above under @ref{Pattern Matching}.
  6962. @item --enable-extended-glob-default
  6963. Set the default value of the @var{extglob} shell option described
  6964. above under @ref{The Shopt Builtin} to be enabled.
  6965. @item --enable-function-import
  6966. Include support for importing function definitions exported by another
  6967. instance of the shell from the environment. This option is enabled by
  6968. default.
  6969. @item --enable-glob-asciirange-default
  6970. Set the default value of the @var{globasciiranges} shell option described
  6971. above under @ref{The Shopt Builtin} to be enabled.
  6972. This controls the behavior of character ranges when used in pattern matching
  6973. bracket expressions.
  6974. @item --enable-help-builtin
  6975. Include the @code{help} builtin, which displays help on shell builtins and
  6976. variables (@pxref{Bash Builtins}).
  6977. @item --enable-history
  6978. Include command history and the @code{fc} and @code{history}
  6979. builtin commands (@pxref{Bash History Facilities}).
  6980. @item --enable-job-control
  6981. This enables the job control features (@pxref{Job Control}),
  6982. if the operating system supports them.
  6983. @item --enable-multibyte
  6984. This enables support for multibyte characters if the operating
  6985. system provides the necessary support.
  6986. @item --enable-net-redirections
  6987. This enables the special handling of filenames of the form
  6988. @code{/dev/tcp/@var{host}/@var{port}} and
  6989. @code{/dev/udp/@var{host}/@var{port}}
  6990. when used in redirections (@pxref{Redirections}).
  6991. @item --enable-process-substitution
  6992. This enables process substitution (@pxref{Process Substitution}) if
  6993. the operating system provides the necessary support.
  6994. @item --enable-progcomp
  6995. Enable the programmable completion facilities
  6996. (@pxref{Programmable Completion}).
  6997. If Readline is not enabled, this option has no effect.
  6998. @item --enable-prompt-string-decoding
  6999. Turn on the interpretation of a number of backslash-escaped characters
  7000. in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt
  7001. strings. See @ref{Controlling the Prompt}, for a complete list of prompt
  7002. string escape sequences.
  7003. @item --enable-readline
  7004. Include support for command-line editing and history with the Bash
  7005. version of the Readline library (@pxref{Command Line Editing}).
  7006. @item --enable-restricted
  7007. Include support for a @dfn{restricted shell}. If this is enabled, Bash,
  7008. when called as @code{rbash}, enters a restricted mode. See
  7009. @ref{The Restricted Shell}, for a description of restricted mode.
  7010. @item --enable-select
  7011. Include the @code{select} compound command, which allows the generation of
  7012. simple menus (@pxref{Conditional Constructs}).
  7013. @item --enable-separate-helpfiles
  7014. Use external files for the documentation displayed by the @code{help} builtin
  7015. instead of storing the text internally.
  7016. @item --enable-single-help-strings
  7017. Store the text displayed by the @code{help} builtin as a single string for
  7018. each help topic. This aids in translating the text to different languages.
  7019. You may need to disable this if your compiler cannot handle very long string
  7020. literals.
  7021. @item --enable-strict-posix-default
  7022. Make Bash @sc{posix}-conformant by default (@pxref{Bash POSIX Mode}).
  7023. @item --enable-usg-echo-default
  7024. A synonym for @code{--enable-xpg-echo-default}.
  7025. @item --enable-xpg-echo-default
  7026. Make the @code{echo} builtin expand backslash-escaped characters by default,
  7027. without requiring the @option{-e} option.
  7028. This sets the default value of the @code{xpg_echo} shell option to @code{on},
  7029. which makes the Bash @code{echo} behave more like the version specified in
  7030. the Single Unix Specification, version 3.
  7031. @xref{Bash Builtins}, for a description of the escape sequences that
  7032. @code{echo} recognizes.
  7033. @end table
  7034. The file @file{config-top.h} contains C Preprocessor
  7035. @samp{#define} statements for options which are not settable from
  7036. @code{configure}.
  7037. Some of these are not meant to be changed; beware of the consequences if
  7038. you do.
  7039. Read the comments associated with each definition for more
  7040. information about its effect.
  7041. @node Reporting Bugs
  7042. @appendix Reporting Bugs
  7043. Please report all bugs you find in Bash.
  7044. But first, you should
  7045. make sure that it really is a bug, and that it appears in the latest
  7046. version of Bash.
  7047. The latest version of Bash is always available for FTP from
  7048. @uref{ftp://ftp.gnu.org/pub/gnu/bash/}.
  7049. Once you have determined that a bug actually exists, use the
  7050. @code{bashbug} command to submit a bug report.
  7051. If you have a fix, you are encouraged to mail that as well!
  7052. Suggestions and `philosophical' bug reports may be mailed
  7053. to @email{bug-bash@@gnu.org} or posted to the Usenet
  7054. newsgroup @code{gnu.bash.bug}.
  7055. All bug reports should include:
  7056. @itemize @bullet
  7057. @item
  7058. The version number of Bash.
  7059. @item
  7060. The hardware and operating system.
  7061. @item
  7062. The compiler used to compile Bash.
  7063. @item
  7064. A description of the bug behaviour.
  7065. @item
  7066. A short script or `recipe' which exercises the bug and may be used
  7067. to reproduce it.
  7068. @end itemize
  7069. @noindent
  7070. @code{bashbug} inserts the first three items automatically into
  7071. the template it provides for filing a bug report.
  7072. Please send all reports concerning this manual to
  7073. @email{bug-bash@@gnu.org}.
  7074. @node Major Differences From The Bourne Shell
  7075. @appendix Major Differences From The Bourne Shell
  7076. Bash implements essentially the same grammar, parameter and
  7077. variable expansion, redirection, and quoting as the Bourne Shell.
  7078. Bash uses the @sc{posix} standard as the specification of
  7079. how these features are to be implemented. There are some
  7080. differences between the traditional Bourne shell and Bash; this
  7081. section quickly details the differences of significance. A
  7082. number of these differences are explained in greater depth in
  7083. previous sections.
  7084. This section uses the version of @code{sh} included in SVR4.2 (the
  7085. last version of the historical Bourne shell) as the baseline reference.
  7086. @itemize @bullet
  7087. @item
  7088. Bash is @sc{posix}-conformant, even where the @sc{posix} specification
  7089. differs from traditional @code{sh} behavior (@pxref{Bash POSIX Mode}).
  7090. @item
  7091. Bash has multi-character invocation options (@pxref{Invoking Bash}).
  7092. @item
  7093. Bash has command-line editing (@pxref{Command Line Editing}) and
  7094. the @code{bind} builtin.
  7095. @item
  7096. Bash provides a programmable word completion mechanism
  7097. (@pxref{Programmable Completion}), and builtin commands
  7098. @code{complete}, @code{compgen}, and @code{compopt}, to
  7099. manipulate it.
  7100. @item
  7101. Bash has command history (@pxref{Bash History Facilities}) and the
  7102. @code{history} and @code{fc} builtins to manipulate it.
  7103. The Bash history list maintains timestamp information and uses the
  7104. value of the @code{HISTTIMEFORMAT} variable to display it.
  7105. @item
  7106. Bash implements @code{csh}-like history expansion
  7107. (@pxref{History Interaction}).
  7108. @item
  7109. Bash has one-dimensional array variables (@pxref{Arrays}), and the
  7110. appropriate variable expansions and assignment syntax to use them.
  7111. Several of the Bash builtins take options to act on arrays.
  7112. Bash provides a number of built-in array variables.
  7113. @item
  7114. The @code{$'@dots{}'} quoting syntax, which expands ANSI-C
  7115. backslash-escaped characters in the text between the single quotes,
  7116. is supported (@pxref{ANSI-C Quoting}).
  7117. @item
  7118. Bash supports the @code{$"@dots{}"} quoting syntax to do
  7119. locale-specific translation of the characters between the double
  7120. quotes. The @option{-D}, @option{--dump-strings}, and @option{--dump-po-strings}
  7121. invocation options list the translatable strings found in a script
  7122. (@pxref{Locale Translation}).
  7123. @item
  7124. Bash implements the @code{!} keyword to negate the return value of
  7125. a pipeline (@pxref{Pipelines}).
  7126. Very useful when an @code{if} statement needs to act only if a test fails.
  7127. The Bash @samp{-o pipefail} option to @code{set} will cause a pipeline to
  7128. return a failure status if any command fails.
  7129. @item
  7130. Bash has the @code{time} reserved word and command timing (@pxref{Pipelines}).
  7131. The display of the timing statistics may be controlled with the
  7132. @env{TIMEFORMAT} variable.
  7133. @item
  7134. Bash implements the @code{for (( @var{expr1} ; @var{expr2} ; @var{expr3} ))}
  7135. arithmetic for command, similar to the C language (@pxref{Looping Constructs}).
  7136. @item
  7137. Bash includes the @code{select} compound command, which allows the
  7138. generation of simple menus (@pxref{Conditional Constructs}).
  7139. @item
  7140. Bash includes the @code{[[} compound command, which makes conditional
  7141. testing part of the shell grammar (@pxref{Conditional Constructs}), including
  7142. optional regular expression matching.
  7143. @item
  7144. Bash provides optional case-insensitive matching for the @code{case} and
  7145. @code{[[} constructs.
  7146. @item
  7147. Bash includes brace expansion (@pxref{Brace Expansion}) and tilde
  7148. expansion (@pxref{Tilde Expansion}).
  7149. @item
  7150. Bash implements command aliases and the @code{alias} and @code{unalias}
  7151. builtins (@pxref{Aliases}).
  7152. @item
  7153. Bash provides shell arithmetic, the @code{((} compound command
  7154. (@pxref{Conditional Constructs}),
  7155. and arithmetic expansion (@pxref{Shell Arithmetic}).
  7156. @item
  7157. Variables present in the shell's initial environment are automatically
  7158. exported to child processes. The Bourne shell does not normally do
  7159. this unless the variables are explicitly marked using the @code{export}
  7160. command.
  7161. @item
  7162. Bash supports the @samp{+=} assignment operator, which appends to the value
  7163. of the variable named on the left hand side.
  7164. @item
  7165. Bash includes the @sc{posix} pattern removal @samp{%}, @samp{#}, @samp{%%}
  7166. and @samp{##} expansions to remove leading or trailing substrings from
  7167. variable values (@pxref{Shell Parameter Expansion}).
  7168. @item
  7169. The expansion @code{$@{#xx@}}, which returns the length of @code{$@{xx@}},
  7170. is supported (@pxref{Shell Parameter Expansion}).
  7171. @item
  7172. The expansion @code{$@{var:}@var{offset}@code{[:}@var{length}@code{]@}},
  7173. which expands to the substring of @code{var}'s value of length
  7174. @var{length}, beginning at @var{offset}, is present
  7175. (@pxref{Shell Parameter Expansion}).
  7176. @item
  7177. The expansion
  7178. @code{$@{var/[/]}@var{pattern}@code{[/}@var{replacement}@code{]@}},
  7179. which matches @var{pattern} and replaces it with @var{replacement} in
  7180. the value of @code{var}, is available (@pxref{Shell Parameter Expansion}).
  7181. @item
  7182. The expansion @code{$@{!@var{prefix}*@}} expansion, which expands to
  7183. the names of all shell variables whose names begin with @var{prefix},
  7184. is available (@pxref{Shell Parameter Expansion}).
  7185. @item
  7186. Bash has @var{indirect} variable expansion using @code{$@{!word@}}
  7187. (@pxref{Shell Parameter Expansion}).
  7188. @item
  7189. Bash can expand positional parameters beyond @code{$9} using
  7190. @code{$@{@var{num}@}}.
  7191. @item
  7192. The @sc{posix} @code{$()} form of command substitution
  7193. is implemented (@pxref{Command Substitution}),
  7194. and preferred to the Bourne shell's @code{``} (which
  7195. is also implemented for backwards compatibility).
  7196. @item
  7197. Bash has process substitution (@pxref{Process Substitution}).
  7198. @item
  7199. Bash automatically assigns variables that provide information about the
  7200. current user (@env{UID}, @env{EUID}, and @env{GROUPS}), the current host
  7201. (@env{HOSTTYPE}, @env{OSTYPE}, @env{MACHTYPE}, and @env{HOSTNAME}),
  7202. and the instance of Bash that is running (@env{BASH},
  7203. @env{BASH_VERSION}, and @env{BASH_VERSINFO}). @xref{Bash Variables},
  7204. for details.
  7205. @item
  7206. The @env{IFS} variable is used to split only the results of expansion,
  7207. not all words (@pxref{Word Splitting}).
  7208. This closes a longstanding shell security hole.
  7209. @item
  7210. The filename expansion bracket expression code uses @samp{!} and @samp{^}
  7211. to negate the set of characters between the brackets.
  7212. The Bourne shell uses only @samp{!}.
  7213. @item
  7214. Bash implements the full set of @sc{posix} filename expansion operators,
  7215. including @var{character classes}, @var{equivalence classes}, and
  7216. @var{collating symbols} (@pxref{Filename Expansion}).
  7217. @item
  7218. Bash implements extended pattern matching features when the @code{extglob}
  7219. shell option is enabled (@pxref{Pattern Matching}).
  7220. @item
  7221. It is possible to have a variable and a function with the same name;
  7222. @code{sh} does not separate the two name spaces.
  7223. @item
  7224. Bash functions are permitted to have local variables using the
  7225. @code{local} builtin, and thus useful recursive functions may be written
  7226. (@pxref{Bash Builtins}).
  7227. @item
  7228. Variable assignments preceding commands affect only that command, even
  7229. builtins and functions (@pxref{Environment}).
  7230. In @code{sh}, all variable assignments
  7231. preceding commands are global unless the command is executed from the
  7232. file system.
  7233. @item
  7234. Bash performs filename expansion on filenames specified as operands
  7235. to input and output redirection operators (@pxref{Redirections}).
  7236. @item
  7237. Bash contains the @samp{<>} redirection operator, allowing a file to be
  7238. opened for both reading and writing, and the @samp{&>} redirection
  7239. operator, for directing standard output and standard error to the same
  7240. file (@pxref{Redirections}).
  7241. @item
  7242. Bash includes the @samp{<<<} redirection operator, allowing a string to
  7243. be used as the standard input to a command.
  7244. @item
  7245. Bash implements the @samp{[n]<&@var{word}} and @samp{[n]>&@var{word}}
  7246. redirection operators, which move one file descriptor to another.
  7247. @item
  7248. Bash treats a number of filenames specially when they are
  7249. used in redirection operators (@pxref{Redirections}).
  7250. @item
  7251. Bash can open network connections to arbitrary machines and services
  7252. with the redirection operators (@pxref{Redirections}).
  7253. @item
  7254. The @code{noclobber} option is available to avoid overwriting existing
  7255. files with output redirection (@pxref{The Set Builtin}).
  7256. The @samp{>|} redirection operator may be used to override @code{noclobber}.
  7257. @item
  7258. The Bash @code{cd} and @code{pwd} builtins (@pxref{Bourne Shell Builtins})
  7259. each take @option{-L} and @option{-P} options to switch between logical and
  7260. physical modes.
  7261. @item
  7262. Bash allows a function to override a builtin with the same name, and provides
  7263. access to that builtin's functionality within the function via the
  7264. @code{builtin} and @code{command} builtins (@pxref{Bash Builtins}).
  7265. @item
  7266. The @code{command} builtin allows selective disabling of functions
  7267. when command lookup is performed (@pxref{Bash Builtins}).
  7268. @item
  7269. Individual builtins may be enabled or disabled using the @code{enable}
  7270. builtin (@pxref{Bash Builtins}).
  7271. @item
  7272. The Bash @code{exec} builtin takes additional options that allow users
  7273. to control the contents of the environment passed to the executed
  7274. command, and what the zeroth argument to the command is to be
  7275. (@pxref{Bourne Shell Builtins}).
  7276. @item
  7277. Shell functions may be exported to children via the environment
  7278. using @code{export -f} (@pxref{Shell Functions}).
  7279. @item
  7280. The Bash @code{export}, @code{readonly}, and @code{declare} builtins can
  7281. take a @option{-f} option to act on shell functions, a @option{-p} option to
  7282. display variables with various attributes set in a format that can be
  7283. used as shell input, a @option{-n} option to remove various variable
  7284. attributes, and @samp{name=value} arguments to set variable attributes
  7285. and values simultaneously.
  7286. @item
  7287. The Bash @code{hash} builtin allows a name to be associated with
  7288. an arbitrary filename, even when that filename cannot be found by
  7289. searching the @env{$PATH}, using @samp{hash -p}
  7290. (@pxref{Bourne Shell Builtins}).
  7291. @item
  7292. Bash includes a @code{help} builtin for quick reference to shell
  7293. facilities (@pxref{Bash Builtins}).
  7294. @item
  7295. The @code{printf} builtin is available to display formatted output
  7296. (@pxref{Bash Builtins}).
  7297. @item
  7298. The Bash @code{read} builtin (@pxref{Bash Builtins})
  7299. will read a line ending in @samp{\} with
  7300. the @option{-r} option, and will use the @env{REPLY} variable as a
  7301. default if no non-option arguments are supplied.
  7302. The Bash @code{read} builtin
  7303. also accepts a prompt string with the @option{-p} option and will use
  7304. Readline to obtain the line when given the @option{-e} option.
  7305. The @code{read} builtin also has additional options to control input:
  7306. the @option{-s} option will turn off echoing of input characters as
  7307. they are read, the @option{-t} option will allow @code{read} to time out
  7308. if input does not arrive within a specified number of seconds, the
  7309. @option{-n} option will allow reading only a specified number of
  7310. characters rather than a full line, and the @option{-d} option will read
  7311. until a particular character rather than newline.
  7312. @item
  7313. The @code{return} builtin may be used to abort execution of scripts
  7314. executed with the @code{.} or @code{source} builtins
  7315. (@pxref{Bourne Shell Builtins}).
  7316. @item
  7317. Bash includes the @code{shopt} builtin, for finer control of shell
  7318. optional capabilities (@pxref{The Shopt Builtin}), and allows these options
  7319. to be set and unset at shell invocation (@pxref{Invoking Bash}).
  7320. @item
  7321. Bash has much more optional behavior controllable with the @code{set}
  7322. builtin (@pxref{The Set Builtin}).
  7323. @item
  7324. The @samp{-x} (@option{xtrace}) option displays commands other than
  7325. simple commands when performing an execution trace
  7326. (@pxref{The Set Builtin}).
  7327. @item
  7328. The @code{test} builtin (@pxref{Bourne Shell Builtins})
  7329. is slightly different, as it implements the @sc{posix} algorithm,
  7330. which specifies the behavior based on the number of arguments.
  7331. @item
  7332. Bash includes the @code{caller} builtin, which displays the context of
  7333. any active subroutine call (a shell function or a script executed with
  7334. the @code{.} or @code{source} builtins). This supports the bash
  7335. debugger.
  7336. @item
  7337. The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a
  7338. @code{DEBUG} pseudo-signal specification, similar to @code{EXIT}.
  7339. Commands specified with a @code{DEBUG} trap are executed before every
  7340. simple command, @code{for} command, @code{case} command,
  7341. @code{select} command, every arithmetic @code{for} command, and before
  7342. the first command executes in a shell function.
  7343. The @code{DEBUG} trap is not inherited by shell functions unless the
  7344. function has been given the @code{trace} attribute or the
  7345. @code{functrace} option has been enabled using the @code{shopt} builtin.
  7346. The @code{extdebug} shell option has additional effects on the
  7347. @code{DEBUG} trap.
  7348. The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows an
  7349. @code{ERR} pseudo-signal specification, similar to @code{EXIT} and @code{DEBUG}.
  7350. Commands specified with an @code{ERR} trap are executed after a simple
  7351. command fails, with a few exceptions.
  7352. The @code{ERR} trap is not inherited by shell functions unless the
  7353. @code{-o errtrace} option to the @code{set} builtin is enabled.
  7354. The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a
  7355. @code{RETURN} pseudo-signal specification, similar to
  7356. @code{EXIT} and @code{DEBUG}.
  7357. Commands specified with an @code{RETURN} trap are executed before
  7358. execution resumes after a shell function or a shell script executed with
  7359. @code{.} or @code{source} returns.
  7360. The @code{RETURN} trap is not inherited by shell functions unless the
  7361. function has been given the @code{trace} attribute or the
  7362. @code{functrace} option has been enabled using the @code{shopt} builtin.
  7363. @item
  7364. The Bash @code{type} builtin is more extensive and gives more information
  7365. about the names it finds (@pxref{Bash Builtins}).
  7366. @item
  7367. The Bash @code{umask} builtin permits a @option{-p} option to cause
  7368. the output to be displayed in the form of a @code{umask} command
  7369. that may be reused as input (@pxref{Bourne Shell Builtins}).
  7370. @item
  7371. Bash implements a @code{csh}-like directory stack, and provides the
  7372. @code{pushd}, @code{popd}, and @code{dirs} builtins to manipulate it
  7373. (@pxref{The Directory Stack}).
  7374. Bash also makes the directory stack visible as the value of the
  7375. @env{DIRSTACK} shell variable.
  7376. @item
  7377. Bash interprets special backslash-escaped characters in the prompt
  7378. strings when interactive (@pxref{Controlling the Prompt}).
  7379. @item
  7380. The Bash restricted mode is more useful (@pxref{The Restricted Shell});
  7381. the SVR4.2 shell restricted mode is too limited.
  7382. @item
  7383. The @code{disown} builtin can remove a job from the internal shell
  7384. job table (@pxref{Job Control Builtins}) or suppress the sending
  7385. of @code{SIGHUP} to a job when the shell exits as the result of a
  7386. @code{SIGHUP}.
  7387. @item
  7388. Bash includes a number of features to support a separate debugger for
  7389. shell scripts.
  7390. @item
  7391. The SVR4.2 shell has two privilege-related builtins
  7392. (@code{mldmode} and @code{priv}) not present in Bash.
  7393. @item
  7394. Bash does not have the @code{stop} or @code{newgrp} builtins.
  7395. @item
  7396. Bash does not use the @env{SHACCT} variable or perform shell accounting.
  7397. @item
  7398. The SVR4.2 @code{sh} uses a @env{TIMEOUT} variable like Bash uses
  7399. @env{TMOUT}.
  7400. @end itemize
  7401. @noindent
  7402. More features unique to Bash may be found in @ref{Bash Features}.
  7403. @appendixsec Implementation Differences From The SVR4.2 Shell
  7404. Since Bash is a completely new implementation, it does not suffer from
  7405. many of the limitations of the SVR4.2 shell. For instance:
  7406. @itemize @bullet
  7407. @item
  7408. Bash does not fork a subshell when redirecting into or out of
  7409. a shell control structure such as an @code{if} or @code{while}
  7410. statement.
  7411. @item
  7412. Bash does not allow unbalanced quotes. The SVR4.2 shell will silently
  7413. insert a needed closing quote at @code{EOF} under certain circumstances.
  7414. This can be the cause of some hard-to-find errors.
  7415. @item
  7416. The SVR4.2 shell uses a baroque memory management scheme based on
  7417. trapping @code{SIGSEGV}. If the shell is started from a process with
  7418. @code{SIGSEGV} blocked (e.g., by using the @code{system()} C library
  7419. function call), it misbehaves badly.
  7420. @item
  7421. In a questionable attempt at security, the SVR4.2 shell,
  7422. when invoked without the @option{-p} option, will alter its real
  7423. and effective @sc{uid} and @sc{gid} if they are less than some
  7424. magic threshold value, commonly 100.
  7425. This can lead to unexpected results.
  7426. @item
  7427. The SVR4.2 shell does not allow users to trap @code{SIGSEGV},
  7428. @code{SIGALRM}, or @code{SIGCHLD}.
  7429. @item
  7430. The SVR4.2 shell does not allow the @env{IFS}, @env{MAILCHECK},
  7431. @env{PATH}, @env{PS1}, or @env{PS2} variables to be unset.
  7432. @item
  7433. The SVR4.2 shell treats @samp{^} as the undocumented equivalent of
  7434. @samp{|}.
  7435. @item
  7436. Bash allows multiple option arguments when it is invoked (@code{-x -v});
  7437. the SVR4.2 shell allows only one option argument (@code{-xv}). In
  7438. fact, some versions of the shell dump core if the second argument begins
  7439. with a @samp{-}.
  7440. @item
  7441. The SVR4.2 shell exits a script if any builtin fails; Bash exits
  7442. a script only if one of the @sc{posix} special builtins fails, and
  7443. only for certain failures, as enumerated in the @sc{posix} standard.
  7444. @item
  7445. The SVR4.2 shell behaves differently when invoked as @code{jsh}
  7446. (it turns on job control).
  7447. @end itemize
  7448. @node GNU Free Documentation License
  7449. @appendix GNU Free Documentation License
  7450. @include fdl.texi
  7451. @node Indexes
  7452. @appendix Indexes
  7453. @menu
  7454. * Builtin Index:: Index of Bash builtin commands.
  7455. * Reserved Word Index:: Index of Bash reserved words.
  7456. * Variable Index:: Quick reference helps you find the
  7457. variable you want.
  7458. * Function Index:: Index of bindable Readline functions.
  7459. * Concept Index:: General index for concepts described in
  7460. this manual.
  7461. @end menu
  7462. @node Builtin Index
  7463. @appendixsec Index of Shell Builtin Commands
  7464. @printindex bt
  7465. @node Reserved Word Index
  7466. @appendixsec Index of Shell Reserved Words
  7467. @printindex rw
  7468. @node Variable Index
  7469. @appendixsec Parameter and Variable Index
  7470. @printindex vr
  7471. @node Function Index
  7472. @appendixsec Function Index
  7473. @printindex fn
  7474. @node Concept Index
  7475. @appendixsec Concept Index
  7476. @printindex cp
  7477. @bye