bashref.texi 345 KB

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