Provided by:
manpages-nl_20051127-4_all
NAAM
bash - GNU Bourne-Again SHell
OVERZICHT
bash [opties] [bestand]
COPYRIGHT
Bash is Copyright (C) 1989-1999 van de Free Software Foundation, Inc.
BESCHRIJVING
Bash is een met sh-overeenkomende opdracht taal interpreteerder die
opdrachten uitvoert die gelezen worden van de standaard invoer, of van
een bestand. Bash implementeert ook bruikbare eigenschappen van de
Korn en C shell’s (ksh en csh).
Bash is bedoeld om overeen te komen met de implementatie van de IEEE
POSIX Shell en Tools specificatie (IEEE Werkgroep 1003.2).
OPTIES
In aanvulling op de enkele-karakter shell opties beschreven in de docu‐
mentatie voor de ingebouwde set opdracht, interpreteert bash de vol‐
gende opties wanneer het aangeroepen wordt:
-c string Als de -c optie aanwezig is, dan worden opdrachten gelezen
van string. Als er argumenten na de string zijn, dan worden
ze toegeschreven aan de plaatsbepaalde grootheden, startend
met $0.
-r Als de -r optie aanwezig is, dan wordt gebruik van de shell
beperkt. (zie BEPERKTE SHELL onder).
-i Als de -i optie aanwezig is dan wordt de shell interactief.
-s Als de -s optie aanwezig is, of als geen argumenten overbli‐
jven na optie verwerking, dan worden opdrachten van standaard
invoer gelezen. Deze optie laat toe dat de plaatsbepaalde
grootheden gezet worden bij het aanroepen van een interac‐
tieve shell.
-v Druk shell invoer regels af als ze gelezen worden.
-x Druk opdrachten en hun argumenten af als ze uitgevoerd wor‐
den.
-D Een lijst van alle, met dubbeleaanhalingstekens geciteerde,
strings voorafgegaan door $ wordt afgedrukt op de standaard
uitvoer. Dit zijn de strings die voorwerp tot taal vertaling
zijn wanneer de huidige localiteit niet C of POSIX is. Dit
impliceert de -n optie; geen opdrachten zullen uitgevoerd
worden.
-- Een -- kondigt het einde van opties aan en schakelt verdere
optieverwerking uit. Mogelijke argumenten na de -- worden
als bestandsnamen en argumenten behandeld. Een argument - is
gelijk aan --.
Bash begrijpt ook een aantal meerkarakter opties. Deze opties moeten
op de opdrachtregel verschijnen vóór de enkele-karakter opties, om
herkenbaar te zijn.
--dump-po-strings
{#--dump-overdraagbare-object-strings#} Gelijk aan -D, maar de
uitvoer is in de GNU gettext po (overdraagbaar object) bestand
vorm.
--dump-strings
{#--dump-strings#} Gelijk aan -D.
--help {#--hulp#} Geef een gebruik bericht op de standaard uitvoer en
eindig geslaagd.
--login
{#--meldt-aan#} Laat bash zich gedragen alsof het aangeroepen
werd als een inlog shell (zie AANROEPEN onder).
--noediting
{#--niet-bewerken,nl#} Gebruik de GNU readline {#lees regel#}
bibliotheek niet om opdracht regels te lezen als interactief.
--noprofile
{#--geen-profiel#} Lees niet het globale systeem opstart bestand
/etc/profile of één van de persoonlijke initialisatiebestanden
~/.bash_profile, ~/.bash_login, of ~/.profile. Standaard leest
bash deze bestanden wanneer het aangeroepen wordt als een inlog
shell (zie AANROEPEN onder).
--norc {#--niet-d(raai)-o(pdrachten)#} Ga niet het persoonlijke ini‐
tialisatiebestand ~/.bashrc lezen en uitvoeren als de shell
interactief is. Deze optie is normaal aan als de shell
aangeroepen wordt als sh.
--posix
{#--"posix"#} Veranderd het gedrag van bash waar het normale
gedrag verschilt van de POSIX 1003.2 standaard om overeen te
komen met de standaard.
--rcfile bestand
{#--d(raai)-o(opdrachten)-bestand#} Voer opdrachten van bestand
uit in plaats van het normale persoonlijke initialisatiebestand
~/.bashrc als de shell interactief is (zie AANROEPEN onder).
--restricted
{#--beperkt#} De shell wordt beperkt (zie BEPERKTE SCHELP
onder).
--verbose
{#--praatgraag#} Gelijk aan -v.
--version
{#--versie#} Geef versie informatie voor deze bash op de stan‐
daard uitvoer en eindig geslaagd.
ARGUMENTEN
Als argumenten overblijven na optie verwerking, en niet de -c nog de -s
optie werd gegeven, dan wordt aangenomen dat het eerste argument de
naam van een bestand met shell opdrachten is. Als bash is aangeroepen
op deze manier, dan wordt $0 gezet naar de naam van het bestand, en de
plaatsbepaalde grootheden worden gezet naar de overblijvende argu‐
menten. Bash leest en voert de opdrachten in dit bestand uit, en
eindigt dan. Bash’s einde status is de einde status van de laatste
opdracht uitgevoerd in het script. Als geen opdrachten werden uitgevo‐
erd is de einde status 0.
AANROEPEN
Een inlog shell in er een wiens eerste karakter van argument nul een -
is, of een gestart met de --login {#--inlog#} optie.
Een interactieve shell is er één waarvan de standaard invoer en uitvoer
allebei met een terminal zijn verbonden (zoals bepaald door isatty(3)),
of één gestart met de -i optie. PS1 wordt gezet en $- bevat i als bash
interactief is; dit staat een shellscript of een opstartbestand toe
deze status te testen.
De volgende alinea’s beschrijven hoe bash zijn opstart bestanden uitvo‐
ert. Als een van de bestanden bestaat maar niet gelezen kan worden dan
rapporteert bash een fout. Tildes worden geëxpandeerd tot bestand
namen zoals beschreven onder bij Tilde Expandering in het VERGROTING
gedeelte.
Wanneer bash is aangeroepen als een interactieve inlog shell, of als
een niet-interactieve shell met de --login {#--inlog#} optie, dan leest
en voert eerst de opdrachten van het bestand /etc/profile uit, als dat
bestand bestaat. Na het lezen van dat bestand zoekt het naar
~/.bash_profile, ~/.bash_login, en ~/.profile, in die volgorde, en
leest en voert de opdrachten uit van de eerste die bestaat en leesbaar
is. De --noprofile {#--geen-profiel#} optie kan gebruikt worden wan‐
neer de shell wordt gestart om dit gedrag te stuiten.
Wanneer een inlog shell eindigt, leest bash de opdrachten van het
bestand ~/.bash_logout en voert ze uit, als het bestaat.
Wanneer een interactieve shell die niet een inlog shell is, start,
leest bash de opdrachten van ~/.bashrc en voert ze uit, als dat bestand
bestaat. Dit kan gestuit worden door de --norc {#--geen-"rc"#} optie
te gebruiken. De --rcfile bestand {#--"rc"bestand#} optie zal bash
dwingen om de opdrachten van bestand te lezen en uit te voeren in
plaats van ~/.bashrc.
Wanneer bash niet-interactief is gestart, om een shell script te
draaien bijvoorbeeld, zoekt het naar de variabele BASH_ENV in de omgev‐
ing, legt zijn waarde uit als het er lijkt te zijn, en gebruikt de
geïnterpreteerde waarde als de naam van een bestand om te lezen en uit
te voeren. Bash gedraagt zich alsof de volgende opdracht was uitgevo‐
erd:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
maar de waarde van de PATH {#weg#} variabele wordt niet gebruikt om de
bestand naam te zoeken.
Als bash werd aangeroepen met de naam sh, probeert het het opstart
gedrag van historische versies van sh zo goed mogelijk na te doen,
onderwijl ook nog voldoend aan de POSIX standaard. Wanneer aangeroepen
als een interactieve inlog shell, of een niet-interactieve shell met de
--login optie, dan probeert het eerst om opdrachten van /etc/profile en
~/.profile, in die volgorde, te lezen en uit te voeren. De --noprofile
{#--geen-profiel#} optie kan gebruikt worden om dit gedrag te stuiten.
Wanneer aangeroepen als een interactieve shell met de naam sh, dan zal
bash naar de variabele ENV, zoeken, en zijn waarde interpreteren als
die bepaald is, en de geïnterpreteerde waarde gebruiken als de naam van
een bestand om te lezen en uit te voeren. Omdat een shell aangeroepen
als sh niet probeert om opdrachten van enig ander opstart bestand te
lezen en uit te voeren, heeft de --rcfile optie geen gevolgen. Een
niet-interactieve shell aangeroepen met de naam sh probeert niet om
enige andere opstart bestanden te lezen. Wanneer aangeroepen als sh,
dan zal bash posix mode ingaan nadat de opstart bestanden gelezen zijn.
Wanneer bash gestart is in posix toestand, zoals met de --posix
opdracht regel optie, dan volgt het de POSIX standaard voor opstart
bestanden. In deze mode leggen interactieve shell’s de ENV variabele
uit en opdrachten worden gelezen en uitgevoerd van het bestand wiens
naam de geïnterpreteerde waarde is. Geen andere opstart bestanden wor‐
den gelezen.
Bash probeert te bepalen of het gedraaid wordt door de op-afstand shell
demoon, gewoonlijk rshd. Als bash bepaalt dat het gedraaid wordt door
rshd leest en voert het opdrachten uit van ~/.bashrc als dat bestand
bestaat en leesbaar is. Het zal dit niet doen als het aangeroepen werd
als sh. De --norc {#--geen"rc"#} optie kan gebruikt worden om dit
gedrag te stuiten en de --rcfile {#--"rc"bestand#} optie mag gebruikt
worden om een ander bestand af te dwingen, maar rshd roept in het alge‐
meen de shell niet aan met deze opties of laat toe om ze op te geven.
Als de shell gestart is met het geldende gebruiker (groep) id ongelijk
aan het echte gebruiker (groep) id, en de -p optie is niet geleverd,
dan worden geen opstart bestanden gelezen, shell functies worden niet
van de omgeving geërfd, de SHELLOPTS variabele, als het in de omgeving
voorkomt, wordt genegeerd, en het geldende gebruiker id wordt gezet
naar het echte gebruiker id. Als de optie
is geleverd bij aanroepen is het opstart gedrag hetzelfde, maar het
geldende gebruiker id is niet her-zet.
BEPALINGEN
De volgende begripsbepalingen worden gebruikt in de rest van dit docu‐
ment.
ruimte Een spatie of tabulatie.
woord Een opeenvolging van karakters die als één geheel worden
beschouwd door de shell. Ook bekend onder de naam voorwerp
{#"token"#}.
naam Een woord bestaande uit alleen alphanumerieke karakters en
onder_streepje {#_#}, en beginnend met een alphabetisch karakter
of een onder_streepje. Ook naar verwezen als identificeerder.
metakarakter
Een karakter dat, wanneer ongeciteerd, woorden scheidt. Een van
de volgende:
| & ; ( ) < > spatie tabulatie
controle operator
Een voorwerp dat een controle functie uitvoert. Het is een van
de volgende symbolen:
|| & && ; ;; ( ) | <nieuwe regel>
Gereserveerde woorden zijn woorden die een bijzondere betekenis voor de
shell hebben. De volgende woorden worden herkent als gereserveerd wan‐
neer ongeciteerd en als het het eerste woord van een simpele opdracht
(zie SCHELP SPELLING onder), of het derde woord van een case of for
opdracht is:
! case do done elif else esac fi for function if in select then until
while { } time [[ ]]
Simpele Opdrachten
Een simpele opdracht is een opeenvolging van eventuele variabele
toekenningen gevolgd door met ruimte-gescheiden woorden en omleidingen,
en beëindigd door een controle operator. Het eerste woord geeft de uit
te voeren opdracht op. De overblijvende woorden worden als argumenten
doorgegeven aan de aangeroepen opdracht.
De teruggeef waarde van een simpele opdracht is zijn einde staat, of
128+n als de opdracht werd beëindigt door een signaal. n.
Pijplijnen
Een pijplijn is een opeenvolging van één of meerdere opdrachten
gescheiden door het karakter |. De vorm voor een pijplijn is:
[time [-p]] [ ! ] opdracht [ | opdracht2 ... ]
De standaard uitvoer van opdracht is verbonden met de standaard invoer
van opdracht2. Deze koppeling wordt uitgevoerd vóór enige omleidingen
opgegeven door de opdracht (zie OMLEIDEN onder).
Als het gereserveerde woord ! voorafgaat aan de pijplijn dan is de
einde status van die pijplijn de logische NIET van de einde status van
de laatste opdracht. Anders is de status van de pijplijn de einde sta‐
tus van de laatste opdracht. De shell wacht tot alle opdrachten in de
pijplijn zijn beëindigd vóór het teruggeven van een waarde.
Als het gereserveerde woord time {#tijd#} aan de pijplijn voorafgaat,
dan worden zowel de verstreken-, de gebruiker- en de systeemtijd veror‐
berd door zijn uitvoering gerapporteerd wanneer de pijplijn eindigt.
De -p optie veranderd de uitvoer vorm naar dat opgegeven door POSIX.
De TIMEFORMAT {#tijd vorm#} variabele mag worden gezet naar een vorm-
string dat opgeeft hoe de tijd informatie weergegeven zouden moeten
worden; zie de beschrijving van TIMEFORMAT onder Shell Variabelen
onder.
Elke opdracht in een pijplijn wordt uitgevoerd als een apart proces
(dat is, in een sub-shell).
Lijsten
Een lijst is een opeenvolging van één of meer pijplijnen gescheiden
door één van de operators ;, &, &&, of , en eventueel beëindigd door
één van ;, &, of <nieuweregel>.
Van deze lijst operatoren hebben && en gelijke voorrang, gevolgd
door ; en &, die dezelfde voorrang hebben.
Als een opdracht beëindigd wordt door de controle operator &, dan voert
de shell de opdracht uit in de achtergrond in een sub-shell. De shell
wacht niet tot de opdracht eindigt, en de teruggeef status is 0.
Opdrachten gescheiden door een ; worden opeenvolgend uitgevoerd; de
shell wacht om de beurt op elke opdracht . De teruggeef status is de
einde status van de laatst uitgevoerde opdracht.
De controle operators && en beschrijven respectievelijk EN lijsten
en OF lijsten. Een EN lijst heeft de vorm
opdracht && opdracht2
opdracht2 wordt uitgevoerd als, en alleen als opdracht een einde status
teruggeeft van nul.
Een OF lijst heeft de vorm
opdracht opdracht2
opdracht2 wordt uitgevoerd als en alleen als opdracht een niet-nul
einde status teruggeeft. De teruggeef status van EN en OF lijsten is de
einde status van de laatst uitgevoerde opdracht in de lijst.
Gecompileerde Opdrachten
Een gecompileerde opdracht is een van de volgende:
(lijst)
lijst wordt uitgevoerd in een sub-shell. Variabele toekenningen
en ingebouwde opdrachten die de shell’s omgeving beïnvloeden
blijven geen gelding houden nadat de opdracht afgerond is. De
teruggeef status is de einde status van lijst.
{ lijst; }
lijst wordt eenvoudig uitgevoerd in de huidige shell omgeving.
lijst moet afgesloten worden met een nieuwe regel of
dubbelepunt. Dit status bekend als een groep opdracht. De
teruggeef status is de einde status van lijst.
((expressie))
De expressie wordt beoordeeld volgens de regels beschreven onder
REKENKUNDIGE BEOORDELING Als de waarde van de expressie niet-nul
is, dan is de teruggeef status 0; anders is de teruggeef status
1. Dit is precies gelijk aan let "expressie".
[[ expressie ]]
Geeft een status terug van 0 of 1 afhankelijk van de beoordeling
van de voorwaardelijke expressie expressie. Expressies worden
gecompileerd uit de onderdelen beschreven onder VOORWAARDELIJKE
UITDRUKKINGEN Woord splitsen en padnaam expandering worden niet
uitgevoerd op de woorden tussen de [[ en ]]; tilde expandering,
grootheid en variabele expandering, rekenkundige expandering,
opdracht substitutie, proces substitutie, en citeer verwijdering
worden wel uitgevoerd.
Wanneer de == en != operators worden gebruikt wordt het string
rechts van de operator als een patroon genomen en gepast volgens
de regels beschreven onder Patroon Passen. De teruggave waarde
is 0 als het string past en anders 1 als het niet past met het
patroon. Elk gedeelte van het patroon mag geciteerd worden om af
te dwingen dat het als een string wordt gepast.
Expressies mogen gecompileerd worden met gebruik van de volgende
expressies, opgegeven in aflopende volgorde van voorrang:
( expressie )
Geeft de waarde van expressie. Dit mag gebruikt worden
om de normale voorrang van operators opzij te zetten.
! expressie
Waar als expressie fout is.
expressie && expressie
Waar als beide expressie1 en expressie2 waar zijn.
expressie1 || expressie2
Waar als expressie1 of expressie2 waar is.
De && en || operators voeren expressie2 niet uit als de waarde van
expressie voldoende is om de teruggeef waarde van de hele voorwaardeli‐
jke expressie te bepalen.
for naam [ in woord ] ; do lijst ; done
De lijst van woorden die in volgt wordt geëxpandeerd, een lijst
van zaken producerend. De variabele naam wordt om de beurt gezet
naar elk element van deze lijst, en lijst wordt elke keer uit‐
gevoerd. Als de in woord weggelaten wordt, dan voert de for
{#voor#} opdracht lijst één keer uit voor elke plaatsbepaalde
grootheid die gezet is (zie GROOTHEDEN onder). De teruggeef
status is de einde status van de laatste opdracht die uitvoert.
Als de expandering van de zaken volgend op in een lege lijst
oplevert worden geen opdrachten uitgevoerd, en de teruggeef sta‐
tus is 0.
select naam [ in woord ] ; do lijst ; done
De lijst van woorden volgend op in wordt geëxpandeerd, een lijst
van zaken opleverend. De set geëxpandeerde woorden wordt afge‐
drukt op de standaard fout uitvoer, elk voorafgegaan door een
nummer. Als de in woord weggelaten wordt, worden de plaats‐
bepaalde grootheden afgedrukt (zie GROOTHEDEN onder). De PS3
prompt wordt dan weergegeven en de een regel wordt gelezen van
de standaard invoer. Als de regel bestaat uit een nummer
overeenkomend met een van de weergegeven woorden, dan wordt de
waarde van naam gezet naar dat woord. Als de regel leeg is wor‐
den de woorden en de prompt opnieuw weergegeven. Als EOF {einde-
van-bestand} gelezen wordt rond de opdracht af. Elke andere
waarde zorgt dat naam naar nul wordt gezet. De gelezen regel
wordt bewaard in de variabele REPLY. De lijst wordt uitgevoerd
na elke optie totdat een break of return opdracht uitgevoerd
wordt. De einde status van select is de einde status van de
laatste opdracht uitgevoerd in lijst, of nul als geen opdrachten
werden uitgevoerd.
case woord in [ ( patroon [ | patroon ] ... ) lijst ;; ] ... esac
Een case opdracht geëxpandeerd eerst woord en probeert het dan
om de beurt te passen op patroon, gebruik makend van dezelfde
pas-regels als voor padnaam expanderingen (zie padnaam Expander
ing onder). Wanneer een overeenkomst gevonden is wordt de bijbe‐
horende lijst uitgevoerd. Na de eerste overeenkomst worden geen
volgende overeenkomsten geprobeerd. De einde status is nul als
geen patronen passen. Anders is het de einde status van de
laatst uitgevoerde opdracht in lijst.
if lijst; then lijst; [ elif lijst; then lijst; ] ... [ else lijst; ]
fi
De if lijst wordt uitgevoerd. Als zijn einde status nul is wordt
de then lijst uitgevoerd. Anders wordt elke elif lijst om de
beurt uitgevoerd, en als de einde status nul is, dan wordt zijn
bijbehorende then lijst uitgevoerd en rond de opdracht af.
Anders wordt de else lijst uitgevoerd als aanwezig. De einde
status is de einde status van de laatst uitgevoerde opdracht, of
nul als geen enkele test waar was.
while lijst; do lijst; done
until lijst; do lijst; done
De while opdracht gaat steeds door met het uitvoeren van de do
lijst zolang als de laatste opdracht in lijst een einde staat
van nul teruggeeft. De until opdracht is gelijk aan de while
opdracht, behalve dat de test omgekeerd wordt; the do lijst
wordt uitgevoerd zolang als de laatste opdracht in lijst een
niet-nul einde status teruggeeft. De einde status van de while
en until opdrachten is de einde staat van de laatst uitgevoerde
do lijst opdracht, of nul als er geen werd uitgevoerd.
[ function ] naam () { lijst; }
Dit bepaalt een functie genaamd naam. Het lichaam van de functie
is de lijst van opdrachten tussen { en }. Deze lijst wordt uit‐
gevoerd telkens als naam wordt opgegeven als de naam van een
simpele opdracht. De einde staat van een functie is de einde
status van de laatst uitgevoerde opdracht in het lichaam. (Zie
FUNCTIES onder.)
OPMERKINGEN
In een niet-interactieve shell, of een interactieve shell waarin de
interactive_comments {#interactieve opmerkingen#} optie van het inge‐
bouwde shopt aan status (zie SCHELP INGEBOUWDE OPDRACHTEN onder),
veroorzaakt een woord dat begint met # dat dat woord en alle overbli‐
jvende woorden op die regel genegeerd worden. Een interactieve shell
zonder dat de interactive_comments aan staat, status geen opmerkingen
toe. De interactive_comments optie is normaal aan in interactieve
shell’s.
CITEREN
Citeren wordt gebruikt om de bijzondere betekenis van bepaalde karak‐
ters of woorden voor de shell te verwijderen. Citeren kan gebruikt wor‐
den om speciale behandeling van bijzondere karakters uit te zetten, om
te voorkomen dat gereserveerde woorden herkent worden door de shell als
zodanig, en om grootheid expandering te voorkomen.
Elk van de metakarakters opgegeven boven, onder BEPALINGEN heeft bij‐
zondere betekenis voor de shell en moet geciteerd worden als ze
zichzelf moeten voorstellen. Er zijn drie citeer manieren: de escape
karakter, enkele aanhalingstekens, en dubbele aanhalingstekens.
Een niet-geciteerde backslash (\) is het escape karakter. Het behoudt
de letterlijke betekenis van het volgende karakter erachter, met uit‐
zondering van <nieuwe regel>. Als een \<nieuwe regel> paar opduikt, en
de backslash is niet zelf geciteerd, de \<nieuwe regel> wordt behandeld
als een doorgaan van de regel (dat is, het wordt verwijderd van de
invoer stroom en wordt feitelijk genegeerd).
Omsluiten van karakters in enkele-aanhalingstekens behoudt de letterli‐
jke waarde van elk karakter binnen de aanhalingstekens. Een enkel-aan‐
halingsteken mag niet voorkomen tussen enkele-aanhalingstekens, zelfs
niet wanneer voorafgegaan door een backslash.
Omsluiten van karakters in dubbele aanhalingstekens behoudt de letter‐
lijke waarde van alle karakters binnen de aanhalingstekens, met uitzon‐
dering van $, , en \. De karakters $ en behouden hun bijzondere
betekenis binnen dubbele-aanhalingstekens. De backslash behoudt zijn
bijzondere betekenis alleen wanneer gevolgd door een van de volgende
karakters $, , ", \, of <newline>. Een dubbel-aanhalingsteken mag
geciteerd worden binnen dubbele aanhalingstekens door het vooraf te
laten gaan door een backslash.
De bijzondere grootheden * en @ hebben bijzondere betekenis wanneer in
dubbele aanhalingstekens (zie GROOTHEDEN onder).
Woorden in do vorm $’string’ worden bijzonder behandeld. Het woord
geëxpandeerd tot string, met backslash-ge-escape’te karakters vervangen
zoals opgegeven door de ANSI C standaard. Terugslag escape opeenvolgin‐
gen, als aanwezig, worden als volgt ontcijfert:
\a let-op (bel)
\b backspace
\e een escape karakter
\f bladzijde doorvoer {#"form feed"#}
\n nieuwe regel
\r regel overhaal
\t horizontale tabulatie
\v verticale tabulatie
\\ backslash
\nnn het karakter wiens ASCII code de octale {#8-tallige#}
waarde nnn is (één tot drie cijfers)
\xnnn het karakter wiens ASCII code de hexadecimale {#16-tal‐
lige#} waarde nnn is (één tot drie cijfers}
Het vertaalde resultaat is enkel-geciteerd, alsof het dollar-teken niet
aanwezig was.
Een dubbel-geciteerde string voorafgegaan door een dollar teken ($) zal
zorgen dat het string vertaald wordt volgens de huidige localiteit.
Als de huidige localiteit C of POSIX is dan wordt het dollar teken
genegeerd. Als het string vertaald en vervangen wordt, dan wordt de
substitutie dubbel-geciteerd.
GROOTHEDEN
Een grootheid is een ding dat waardes opslaat. Het kan een naam, een
nummer, of één van de bijzondere karakters onder opgenoemd zijn bij
Bijzondere Grootheden. Voor de shell’s doeleinden is een variabele een
grootheid beschreven door een naam.
Een grootheid is gezet als het een waarde toegekend is. Het nul string
is een geldige waarde. Als een variabele eenmaal is gezet, kan het
alleen ge-onzet worden door de unset ingebouwde opdracht te gebruiken
(zie SCHELP INGEBOUWDE OPDRACHTEN onder).
Aan een variabele mag mag toegekend worden door een opdracht met de
vorm
naam=[waarde]
Als waarde niet is gegeven dan wordt de variabele het nul string
toegekend. Alle waardes ondergaan tilde expandering, grootheid en vari‐
abele expandering, string expandering, opdracht substitutie,
rekenkundige expandering, en citerings verwijdering (zie VERGROTING
onder). Als de variabele zijn heel-getal {#integer#} eigenschap aan
heeft staan (zie maak-bekend {#declare#} onder in SCHELP INGEBOUWDE
OPDRACHTEN) dan is waarde voorwerp voor rekenkundige expandering zelfs
als de $((...)) expandering niet wordt gebruikt (zie Rekenkundige
Expandering onder). Woord splitsen wordt niet gedaan, met uitzondering
van "$@" zoals onder geïnterpreteerd bij Bijzondere Grootheden padnaam
expandering wordt niet gedaan.
Plaatsbepaalde Grootheden
Een plaatsbepaalde grootheid is een grootheid aangeduid door één of
meer cijfers, anders dan het enkele cijfer 0. Plaatsbepaalde grootheden
worden toegekend van de shell’s argumenten wanneer het wordt
aangeroepen, en mogen hertoegekend worden met de ingebouwde set
opdracht. Aan plaatsbepaalde grootheden mag niet toegekend worden met
een toekennings verklaring. De plaatsbepaalde grootheden worden
tijdelijk vervangen wanneer een shell functie wordt uitgevoerd (zie
FUNCTIES onder).
Wanneer een plaatsbepaalde grootheid bestaande uit meer dan een enkel
cijfer geëxpandeerd wordt moet het omsloten worden door haakjes (zie
VERGROTEN onder).
Bijzondere Grootheden
De shell behandeld verschillende grootheden bijzonder. Deze grootheden
mogen alleen bevraagt worden; toekennen aan hen is niet toegestaan.
* Expandeert tot de plaatsbepaalde grootheden, startend van één.
Wanneer de expandering optreed binnen dubbele-aanhalingstekens,
geëxpandeerd het tot een enkel woord met de waarde van elke
grootheid gescheiden door het eerste karakter van de bijzondere
variabele IFS Dus, "$*" is gelijk aan "$1c$2c...", waar c het
eerste karakter is van de waarde van de IFS variabele. Als IFS
niet is gezet worden de grootheden gescheiden door spaties. Als
IFS nul is worden de grootheden samengevoegd zonder
tussenkomende scheiders.
@ Expandeert tot de plaatsbepaalde grootheden, startend van één.
Wanneer de expandering optreed binnen dubbele-aanhalingstekens
wordt elke grootheid geëxpandeerd tot een afzonderlijk woord.
Dus, "$@" is gelijk aan "$1" "$2" ... Wanneer er geen plaats‐
bepaalde grootheden zijn, expanderen $@" en $@ tot niets (dat
is, ze worden verwijderd).
# Expandeert tot het aantal plaatsbepaalde grootheden in deci‐
malen.
? Expandeert tot de status van de meest recent uitgevoerde voor‐
grond pijplijn.
- Expandeert tot de huidige optie vlaggen zoals opgegeven bij aan‐
roeping, door de ingebouwde set opdracht, of die door de shell
zelf zijn gezet. (zoals de -i optie).
$ Expandeert tot het proces ID van de shell. In een () sub-shell,
geëxpandeerd het tot het proces ID van de huidige shell, niet de
sub-shell.
! Expandeert tot het proces ID van de meest recent uitgevoerde
achtergrond (ongelijktijdige) opdracht.
0 Expandeert tot de naam van de shell of shell script. Dit wordt
gezet bij de shell initialisatie {#"initialization"#}. Als bash
aangeroepen is met een bestand met opdrachten dan wordt $0 gezet
naar de naam van dat bestand. Als bash gestart is met de -c
optie, dan wordt $0 gezet naar het eerste argument na het string
dat uitgevoerd zal worden, als er één aanwezig is. Anders wordt
het gezet naar de bestandnaam gebruikt om bash, aan te roepen,
zoals gegeven door argument nul.
_ Bij shell opstarten wordt dit gezet naar de absolute bestand
naam van de shell of shell script dat uitgevoerd wordt zoals
doorgegeven in de argumenten lijst. Daarna geëxpandeerd het
naar het laatste argument van de vorige opdracht, na expander‐
ing. Ook gezet naar de volle bestandnaam van elke uitgevoerde
opdracht en geplaatst in de omgeving overgedragen naar die
opdracht. Bij ophalen van post bevat deze grootheid de naam van
het post bestand dat momenteel bekeken wordt.
Shell s Variabelen
De volgende variabelen zijn gezet door de shell:
PPID Het proces ID van de shell’s ouder. Deze variabele is alleen-
lezen.
PWD De huidige werk directorie zoals gezet door de cd opdracht.
OLDPWD De vorige werk directorie zoals gezet door de cd opdracht.
REPLY Gezet naar de regel invoer gelezen door de read ingebouwde
opdracht wanneer geen argumenten worden gegeven.
UID Expandeert tot het gebruiker ID van de huidige gebruiker,
geïnitialiseerd bij shell opstarten. Deze variabele is alleen-
lezen.
EUID Expandeert tot het geldige gebruiker ID van de huidige
gebruiker, geïnitialiseerd bij shell opstarten. Deze variabele
is alleen-lezen.
GROUPS Een tabel variabele die de lijst van groepen waar de huidige
gebruiker lid van is bevat. Deze variabele is alleen-lezen.
BASH Expandeert tot de volle bestandnaam gebruikt om deze uitvoering
van bash aan te roepen.
BASH_VERSION
Expandeert tot een string die de versie van deze uitvoering van
bash beschrijft.
BASH_VERSINFO
Een alleen-lezen tabel variabele wiens leden versie informatie
bevatten voor deze uitvoering van bash. De waardes toegekend
aan de tabel leden zijn als volgt:
BASH_VERSINFO[0] Het majeur versie nummer (de vrijgave
{#"release"#}).
BASH_VERSINFO[1] Het mineur versie nummer (de versie).
BASH_VERSINFO[2] Het plak niveau {#"patch level"#}.
BASH_VERSINFO[3] De bouw versie.
BASH_VERSINFO[4] De vrijgave status (dat is, beta1).
BASH_VERSINFO[5] De waarde van MACHTYPE {#machine
soort#}.
SHLVL Elke keer verhoogt met 1 als een uitvoering van bash wordt ges‐
tart.
RANDOM Elke keer dat deze grootheid bekeken wordt, wordt een chaotisch
heel getal tussen 0 en 32767 geproduceerd. De opeenvolging van
chaotische nummers mag worden geïnitialiseerd door een waarde
aan RANDOM toe te kennen. Als RANDOM ont-gezet verliest het
zijn bijzondere eigenschappen, zelfs als het daarna her-zet
wordt.
SECONDS
Elke keer dat deze grootheid aangehaald wordt, wordt het aantal
seconden sinds het aanroepen van de shell teruggegeven. Als een
waarde is toegekend aan SECONDS, dan is de teruggegeven waarde
bij volgende aanhalingen het aantal seconden sinds de toekenning
plus de toegekende waarde. Als SECONDS ont-gezet wordt verliest
het zijn bijzondere eigenschappen, zelfs als het daarna wordt
her-zet.
LINENO Elke keer dat deze grootheid aangehaald wordt vervangt de shell
het met een decimaal nummer dat het huidige serie regel nummer
(startend vanaf 1) binnen een script of functie. Wanneer niet in
een script of functie, de vervangende waarde heeft niet gegaran‐
deerd betekenis. Als LINENO ont-gezet wordt verliest het zijn
bijzondere eigenschappen, zelfs als het daarna wordt her-zet.
HISTCMD
Het geschiedenis nummer, of de index in de geschiedenis lijst
van de huidige opdracht. Als HISTCMD ont-gezet wordt verliest
het zijn bijzondere eigenschappen, zelfs als het daarna her-zet
wordt.
DIRSTACK
Een tabel variabele (zie Tabellen onder) die de huidige inhoud
van de directorie stapel bevat. Directories verschijnen in de
stapel in de volgorde waardin ze weergegeven worden door het
directories ingebouwde. Toekennen aan leden van deze tabel
variabele kan gebruikt worden om directories te veranderen die
al op de stapel staan, maar de pushd en popd ingebouwden moeten
gebruikt worden om directories toe te voegen of te verwijderen.
Toekennen aan deze variabele zal de huidige directorie niet
veranderen. Als DIRSTACK ont-gezet wordt verliest het zijn bij‐
zondere eigenschappen, zelfs als het daarna her-zet wordt.
PIPESTATUS
Een tabel variabele (zie Tabellen onder) die een lijst bevat met
einde status waardes van de processen in de meest recent uit‐
gevoerde voorgrond pijplijn (die een enkele opdracht mag bevat‐
ten).
OPTARG De waarde van het laatste optie argument verwerkt door de
getopts ingebouwde opdracht (zie SCHELP INGEBOUWDE OPDRACHTEN
onder).
OPTIND De index van het volgende argument dat verwerkt zal worden door
de getopts ingebouwde opdracht (zie SCHELP INGEBOUWDE OPDRACHTEN
onder).
HOSTNAME
Vanzelf gezet naar de naam van de huidige machine.
HOSTTYPE
Vanzelf gezet naar het string dat een unieke beschrijving van
het soort machine waar bash op draait geeft. Normaal is dat
systeem-afhankelijk.
OSTYPE Vanzelf gezet naar het string dat het besturingssysteem beschri‐
jft waar bash op draait. Normaal is dat systeem-afhankelijk.
MACHTYPE
Vanzelf gezet naar een string dat volledig de systeem soort waar
bash op draait beschrijft, in de standaard GNU cpu-company-sys‐
tem vorm. Normaal is dat systeem-afhankelijk.
SHELLOPTS
Een met dubbele-punten gescheiden lijst van aangezette shell
opties. Elk woord in de lijst is een geldig argument voor de -o
optie van de set ingebouwde opdracht (zie SCHELP INGEBOUWDE
OPDRACHTEN onder). De opties die in SHELLOPTS verschijnen zijn
dezelfde die als on {#aan#} gerapporteerd worden door set -o.
by set -o. Als deze variabele in de omgeving is wanneer bash
opstart, dan wordt elke shell optie in de lijst aangezet vóór
het lezen van enige opstart bestanden. Deze variabele is
alleen-lezen.
De volgende variabelen worden gebruikt door de shell. In sommige
gevallen kent bash een standaard waarde toe aan de variabele; deze
gevallen worden opgemerkt onder.
IFS De Internal Field Separator {#interne veld scheider#} die wordt
gebruikt voor woord splitsen na expandering en om regels in
woorden te splitsen met de read ingebouwde opdracht. De stan‐
daard waarde is ‘‘<spatie><tabulatie><nieuwe regel>’’.
PATH De zoekweg voor opdrachten. Het is een dubbelepunt gescheiden
lijst van directories waarin de shell zoekt naar opdrachten (zie
OPDRACHT UITVOERING onder). De standaard pad is systeem-
afhankelijk, en wordt gezet door de administrator die bash
installeert. Een wijdverbreide waarde is
‘‘/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:.’’.
HOME De thuis directorie van de huidige gebruiker; de het ’door-val’
argument voor de cd ingebouwde opdracht. De waarde van deze
variabele wordt ook gebruikt wanneer tilde expandering wordt
uitgevoerd.
CDPATH De zoekpad voor de cd opdracht. Dit is een dubbele-punten
gescheiden lijst van directories waarin de shell zoekt naar doel
directories opgegeven door de cd opdracht. Een mogelijke waarde
is ‘‘.:~:/usr’’.
BASH_ENV
Als deze grootheid gezet is wanneer bash een shell script uitvo‐
ert wordt zijn waarde geïnterpreteerd als een bestandnaam die
opdrachten bevat om de shell in te wijden, zoals in ~/.bashrc.
De waarde van BASH_ENV is voorwerp voor grootheid expandering,
opdracht substitutie, en rekenkundige expandering voordat het
geïnterpreteerd wordt als een bestand naam. PATH wordt niet
gebruikt om de opgeleverde bestandnaam te zoeken.
MAIL Als deze grootheid gezet is naar een bestand naam en de MAILPATH
variabele is niet gezet dan informeert bash de gebruiker van het
aankomen van post in het opgegeven bestand.
MAILCHECK
Bepaald hoe vaak (in seconden) bash test op post. De standaard
is 60 seconden. Wanneer het tijd is om voor post te testen, dan
doet de shell dat vóór het weergeven van de belangrijkste
{#"primary"#} prompt. Als deze variabele ongezet is dan zet de
shell post testen uit.
MAILPATH
Een dubbele-punten gescheiden lijst van bestandnamen die op post
getest zullen worden. Het bericht dat afgedrukt zal worden wan‐
neer post aankomt in een bepaald bestand kan opgegeven worden
door de bestandnaam van het bericht te scheiden met een ‘?’.
Wanneer gebruikt in de tekst van het bericht geëxpandeerd $_ tot
de naam van het huidige postbestand {#mailbox#}. Voorbeeld:
MAILPATH=’/usr/spool/mail/bfox?"U heeft post":~/shell-mail?"$_
heeft post!"’
Bash levert een standaard waarde voor deze variabele, maar de
plaats van de gebruiker post bestanden die het gebruikt zijn
systeem afhankelijk (dat is, /usr/spool/mail/$USER).
PS1 De waarde van deze grootheid wordt geëxpandeerd (zie PROMPTEN
onder) en gebruikt als het belangrijkste prompt string. De stan‐
daard waarde is ‘‘\s-\v\$ ’’.
PS2 De waarde van deze grootheid wordt geëxpandeerd zoals met PS1 en
wordt gebruikt als de tweede prompt string. De standaard is ‘‘>
’’.
PS3 De waarde van deze grootheid wordt gebruikt als de prompt voor
de select opdracht (zie SCHELP SPELLING boven).
PS4 De waarde van deze grootheid wordt geëxpandeerd zoals met PS1 en
de waarde wordt afgedrukt vóór elke opdracht die bash weergeeft
tijdens een uitvoerings-volgen {#"trace"#}. Het eerste karakter
van PS4 wordt meerdere keren herhaald, als nodig, om meerder
niveaus van omleiden aan te geven. De standaard is ‘‘+ ’’.
TIMEFORMAT
De waarde van deze grootheid wordt gebruikt voor het vorm string
dat opgeeft hoe de tijdinformatie voor pijplijnen weergegeven
moeten worden waar het time gereserveerde woord aan voorafgaat.
Het % karakter begint een escape opeenvolging die geëxpandeerd
wordt naar de tijd waarde of andere informatie. De escape
opeenvolgingen en hun betekenissen zijn als volgt; de haakjes
beschrijven niet vereiste gedeeltes.
%% Een letterlijke %.
%[p][l]R De verstreken tijd in seconden.
%[p][l]U Het aantal CPU seconden verbruikt in gebruiker mode.
%[p][l]S Het aantal CPU seconden verbruikt in systeem mode.
%P Het CPU percentage, berekend met (%U + %S) / %R.
De niet vereiste p is een cijfer dat de precisie opgeeft, het
aantal fractie cijfers na een tientallige punt. Een waarde van
0 veroorzaakt dat geen decimale punt en fractie worden
weergegeven. Maximaal mogen drie plaatsen van de tientallige
punt worden opgegeven; waardes van p groter dan 3 worden veran‐
derd in 3. Als p niet opgegeven wordt, wordt de waarde 3
gebruikt.
De niet vereiste l geeft een langere vorm op die ook minuten
bevat, in de vorm MMmSS.FFs. De waarde van p bepaalt al of niet
de fractie bijgevoegd wordt.
Als deze variabele niet is gezet, gedraagt bash zich alsof het
de waarde $ \nreal\t%3lR\nuser\t%3lU\nsys%3lS had. Als de
waarde nul is worden geen tijdinformatie weergegeven. Een
navolgende nieuwe regel wordt toegevoegd wanneer het vorm string
weergegeven wordt.
HISTSIZE
Het aantal opdrachten te onthouden in de opdrachten geschiedenis
(zie HISTORY onder). De standaard waarde is 500.
HISTFILE
De naam van het bestand waarin de opdrachten geschiedenis wordt
bewaard (zie GESCHIEDENIS onder). De standaard waarde is
~/.bash_history. Als ongezet wordt de opdrachten geschiedenis
niet bewaard wanneer een interactieve shell eindigt.
HISTFILESIZE
Het maximale aantal regels in het geschiedenis bestand. Wanneer
deze variabele een waarde wordt toegekend wordt het geschiedenis
bestand afgehakt als nodig om niet meer dan dat aantal regels te
bevatten. De standaard waarde is 500. Het geschiedenis bestand
wordt ook afgehakt naar deze maat na wegschrijven als een inter‐
actieve shell eindigt.
OPTERR Als gezet naar de waarde 1 geeft bash fout berichten weer die
gemaakt zijn door de getopts ingebouwde opdracht (zie SCHELP
INGEBOUWDE OPDRACHTEN onder). OPTERR is geïnitialiseerd als 1
elke keer dat de shell wordt aangeroepen of een shell script
wordt uitgevoerd.
LANG Gebruikt om de localiteit categorie voor elke categorie niet
expliciet gekozen met een variabele startend met LC_.
LC_ALL Deze variabele zet de waarde van LANG opzij en elke andere LC_
variabele die een localiteit opgeeft.
LC_COLLATE
Deze variabele bepaalt de regels, gebruikt bij het collationeren
van de resultaten van padnaamexpandering, en bepaalt het gedrag
van intervalexpressies, equivalentieklassen en gesorteerde reek‐
sen binnen padnaamexpandering en patroon passen.
LC_CTYPE
Deze variabele bepaalt de uitleg van karakters en het gedrag van
karakter classes binnen padnaam expandering en patroon passen.
LC_MESSAGES
Deze variabele bepaalt de localiteit gebruikt om dubbele-aanhal‐
ingstekens geciteerde strings voorafgegaan door een $.
PROMPT_COMMAND
Als gezet wordt de waarde uitgevoerd als een opdracht vóór het
neerzetten van de belangrijkste (eerste) prompt.
IGNOREEOF
Controleert wat een interactieve shell doet bij ontvangst van
een EOF karakter als de enige invoer. Als gezet is de waarde het
aantal aansluitende EOF karakters die getypt moeten worden als
de eerste karakters van een invoer regel vóór bash eindigt. Als
de variabele bestaat maar geen numerieke waarde heeft, of hele‐
maal geen waarde heeft is de standaard waarde 10. Als het niet
bestaat betekend, EOF het einde van de invoer voor de shell.
TMOUT Als gezet naar een waarde groter dan nul wordt de waarde
geïnterpreteerd als het aantal seconden die gewacht moeten wor‐
den voor invoer na het neerzetten van de belangrijkste (eerste)
prompt. Bash eindigt na het wachten van zoveel seconden als
invoer niet binnenkomt.
FCEDIT De door-val editor voor de fc ingebouwde opdracht.
FIGNORE
Een dubbele-punten gescheiden lijst van achtervoegsels die
genegeerd worden bij het uitvoeren van bestandnaam completeren
(zie READLINE onder). Een bestandnaam wiens achtervoegsel
overeenkomt met de zaken in FIGNORE wordt buitengesloten van de
lijst met gepaste bestandnamen. Een mogelijke waarde is
‘‘.o:~’’.
GLOBIGNORE
Een dubbele-punten gescheiden lijst van patronen die de set
bestandnamen bepaalt die genegeerd zullen worden bij padnaam
expandering. Als een bestandnaam past op een padnaam expander‐
ing patroon ook past op één van de patronen in GLOBIGNORE, dan
wordt het verwijderd van de lijst overeenkomsten.
INPUTRC
De bestandnaam voor het readline opstart bestand, de standaard
~/.inputrc opzij zettend (zie READLINE onder).
HISTCONTROL
Als gezet naar de waarde ignorespace, worden regels die beginnen
met een spatie karakter niet in de geschiedenis lijst gezet. Als
gezet naar de waarde ignoredups, worden regels die overeenkomen
met de laatste geschiedenis regel niet bijgevoegd. De waarde
ignoreboth combineert de twee mogelijkheden. Als niet gezet of
als gezet naar enige andere waarde dan die boven worden alle
regel gelezen door de verwerker bewaard in de geschiedenis
lijst, voorwerp voor de waarde van HISTIGNORE. Deze variabele
zijn functie wordt overstegen door HISTIGNORE. De tweede en
volgende regels van een meerdere-regel gecompileerde opdracht
worden niet getest, en worden bij de geschiedenis gevoegd wat de
waarde van HISTCONTROL ook is.
HISTIGNORE
Een dubbele-punten gescheiden lijst van patronen gebruikt om te
beslissen welke opdracht regels bewaard moeten worden in de
geschiedenis lijst. Elk patroon wordt verankerd bij het begin
van de regel en moet volledig de regel opgeven (geen impliciete
‘*’ wordt achtergevoegd). Elk patroon wordt getest tegen de
regel nadat de tests opgegeven door HISTCONTROL zijn toegepast.
In aanvulling op de normale shell patroon karakters, ‘&’ komt
overeen met de vorige geschiedenis regel. ‘&’ mag ge-escape’t
worden met gebruik van een backslash {#vóór proberen te passen.
De tweede en volgende regels van een meerdere-regel gecom‐
pileerde opdracht worden niet getest, en worden gevoegd bij de
geschiedenis geen acht slaande op de waarde van HISTIGNORE.
histchars
De twee of drie karakters die geschiedenis expandering en zaak‐
maken {#"tokenization"#} controleren (zie GESCHIEDENIS VERGROT
ING onder). Het eerste karakter is het geschiedenis expandering
karakter het karakter dat het begin van geschiedenis expandering
aangeeft, normaal ‘!’. Het tweed karakter is het snelle substi‐
tutie karakter, dat wordt gebruikt als afkorting voor het her-
draaien van de vorige gegeven opdracht, één string voor een
ander vervangend in de opdracht. De door-val is ‘^’. Het niet
vereiste derde karakter is het karakter dat aangeeft dat het
overblijvende gedeelte van de regel een opmerking is wanneer
gevonden als het eerste karakter van een woord, normaal ‘#’. Het
geschiedenis opmerking karakter veroorzaakt dat geschiedenis
substitutie wordt overgeslagen voor de rest van de woorden op de
regel. Het maakt niet dat de shell’s verwerker de rest van de
regel noodzakelijk als een opmerking behandeld.
HOSTFILE
Bevat de naam van een bestand in dezelfde vorm als /etc/hosts
dat gelezen zou moeten worden wanneer de shell een machinenaam
moet completeren. Het bestand mag interactief veranderd worden;
de volgende keer dat machinenaam completeren wordt geprobeerd
bash voegt de inhoud van het nieuwe bestand toe aan de al
bestaande database.
auto_resume
Deze variabele controleert hoe de shell met de gebruiker en taak
controle omgaat. Als deze variabele is gezet worden enkele woord
simpele opdrachten zonder omleidingen behandeld als kandidaten
voor doorgaan van een bestaande gestopte taak. Er wordt geen
tweeslachtigheid toegestaan; als er meer dan één taak is die
begint met de getypte taak wordt de meest recente taak gekozen.
De naam van een gestopte taak, in deze context, is de opdracht
regel gebruikt om het te starten. Als gezet naar de waarde
exact, moet het opgegeven string de naam van de gestopte taak
exact passen; als gezet naar sub-string, moet het opgegeven
string een sub-string passen van de de naam van een gestopte
taak. De sub-string waarde waarde levert diensten lijkend op de
%? taak identificeerder (zie TAAK CONTROLE onder). Als gezet
naar enige andere waarde, moet het gegeven string een voor‐
voegsel zijn van een gestopte taak naam; dit levert diensten
lijkend op de % taak identificeerder.
Tabellen
Bash levert één-dimensionale tabel variabelen. Elke variabele mag
gebruikt worden als een tabel; de declare ingebouwde zal een tabel
expliciet bekend maken. Er is geen maximum grens op de grootte van een
tabel, nog enige vereiste dat de leden aansluitend ge-index’t of
toegekend moeten worden. Tabellen worden ge-index’t met hele getallen
en zijn nul-gebaseerd.
Een tabel wordt vanzelf gemaakt als enige variabele een waarde wordt
toegekend met de spelling naam[index]=waarde. De index wordt behandeld
als een rekenkundige expressie die een nummer moet opleveren groter of
gelijk aan nul. Om expliciet een tabel bekend te maken, gebruik declare
-a naam (zie SCHELP INGEBOUWDE OPDRACHTEN onder). declare -a
naam[index] wordt ook geaccepteerd; de index wordt genegeerd. Eigen‐
schappen mogen opgegeven worden voor een tabel variabele met gebruik
van de declare en readonly ingebouwden. Elke eigenschap gaat op voor
alle leden van een tabel.
Aan tabellen wordt toegekend met gebruik van gecompileerde toekenningen
van de vorm naam naam=(waarde1 ... waarden), waar elke waarde van de
vorm [index]=string is. Alleen string wordt vereist. Als De niet
vereiste rechte haakjes en index worden gegeven wordt aan die index
toegekend; anders aan de index van het element waaraan het laatst werd
toegekend door een opdracht plus één. Indexen start bij nul. Deze
spelling wordt ook geaccepteerd door de declare ingebouwde. Aan indi‐
viduele tabel elementen mag worden toegekend met de naam[index]=waard
spelling boven besproken.
Elk element van een tabel mag bezocht worden met ${naam[index]}. De
haakjes zijn nodig om ruzie met padnaam expandering te voorkomen. Als
index, @ of * is, geëxpandeerd het woord tot alle leden van naam. Deze
indexen verschillen alleen wanneer het woord in dubbele-aanhaling‐
stekens verschijnt. Als het woord met dubbele aanhalingstekens is
geciteerd geëxpandeerd ${naam[*]} tot een enkel woord met de waarde van
elk tabel lid gescheiden door het eerste karakter van de IFS bijzondere
variabele, en ${naam[@]} geëxpandeerd elk element van naam naar een
enkel woord. Wanneer er geen tabel leden zijn, geëxpandeerd ${naam[@]}
tot niets. Dit is gelijksoortig met het expanderen van de bijzondere
grootheden * en @ (zie Bijzondere Grootheden boven). ${#naam[index]}
geëxpandeerd tot de lengte van ${naam[index]}. Als index, * of @ is
geëxpandeerd het tot het aantal elementen in de tabel. Bezoeken van een
tabel variabele zonder een index is gelijk aan het bezoeken van element
nul.
De unset ingebouwde wordt gebruikt om tabellen te vernietigen. unset
naam[index] vernietigd het tabel element bij index index. unset naam,
waar naam een tabel is, of unset naam[index], waar index, * of @ is,
verwijderd de hele tabel.
De declare, local, en readonly ingebouwden accepteren elk een -a optie
om een tabel op te geven. De read ingebouwde accepteert een -a optie om
een lijst woorden gelezen van de standaard invoer toe te kennen aan een
tabel. De set en declare ingebouwden geven tabel waardes weer op een
manier die toestaat ze als toekenningen te gebruiken.
VERGROTING
Expandering wordt uitgevoerd op de opdracht regel nadat het gesplitst
is in woorden. Er worden zeven soorten expandering: haakjes expander‐
ing, tilde expandering, grootheid en variabele expandering, opdracht
substitutie, rekenkundige expandering, woord splitsen, en padnaam
expandering.
De volgorde van expandering is: haakjes expandering, tilde expandering,
grootheid expandering, variabele en rekenkundige expandering en
opdracht substitutie (op van-links-naar-rechts manier), woord splitsen,
ne padnaam expandering.
Op systemen die het ondersteunen is er nog een expandering beschikbaar:
proces substitutie.
Alleen haakjes expandering, woord splitsen en padnaam expandering kun‐
nen het aantal woorden van de expandering veranderen; andere
expanderingen expanderen een enkel woord tot een enkel woord. De enige
uitzondering voor dit zijn de expanderingen van "$@" en "${naam[@]}"
zoals boven geïnterpreteerd (zie GROOTHEDEN).
Haakjes Expandering
Haakjes expandering is een mechanisme waarmee willekeurige strings kun‐
nen worden gemaakt. Dit mechanisme is gelijksoortig aan padnaam
expandering, maar de gemaakte bestandnamen hoeven niet te bestaan.
Patronen die haakjes geëxpandeerd zullen worden nemen de vorm aan van
een niet vereist voorwoord, gevolgd door een serie komma-gescheiden
strings tussen een paar haakjes, gevolgd door een niet vereist nawoord.
Het voorwoord wordt vooraan elk string dat de haakjes bevatten gezet,
en het nawoord wordt achteraan elk opgeleverd string gezet, expanderend
van links naar rechts.
Haakjes expandering mag genest worden. De resultaten van elke
geëxpandeerd string worden niet gesorteerd; links naar rechts volgorde
wordt behouden. Bijvoorbeeld, z{i,a,o}g geëxpandeerd tot ‘zig zag
zog’.
Haakjes expandering wordt uitgevoerd vóór elke andere expandering, en
elk karakter dat bijzondere betekenis heeft voor een andere expandering
wordt behouden in het resultaat. Het is puur tekstueel. Bash past geen
spellings uitleg toe op de context van de expandering of de text tussen
de haakjes.
Een goed gevormde haakjes expandering moet ongeciteerde openende en
sluitende haakjes bevatten, en tenminste één ongeciteerde komma. Elke
niet goed gevormde haakjes expandering blijft onveranderd. Een { of ,
mag geciteerd worden met een backslash om te voorkomen dat het als een
onderdeel van de haakjes expandering wordt gezien.
Dit bouwsel wordt typisch gebruikt als een afkorting wanneer het
algemene voorvoegsel voor de strings langer is dan in het bovenstaande
voorbeeld:
mkdir /usr/local/src/bash/{old,new,dist,bugs}
of
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
Haakjes expandering introduceert een kleine niet-overeenkomst met his‐
torische versies van sh. sh behandeld openende of sluitende haakjes
niet bijzonder wanneer ze verschijnen als deel van een woord, en
behoudt ze in de uitvoer. Bash verwijderd haakjes van woorden als
gevolg van haakjes expandering. Bijvoorbeeld, een woord gegeven in sh
als bestand{1,2} verschijnt overeenkomstig op de uitvoer. Hetzelfde
woord wordt uitgevoerd als bestand1 bestand2 na expandering door bash.
Als precieze overeenkomst met sh verlangt wordt, start bash met de +B
optie of maak haakjes expandering ongedaan met de +B optie voor de set
opdracht (zie SCHELP INGEBOUWDE OPDRACHTEN onder).
Tilde Expandering
Als een woord begint met een ongeciteerd tilde karakter (‘~’), alle
karakters voorafgaand aan de eerste ongeciteerde ‘slag’ {#/#} (of alle
karakters als er geen ongeciteerde slash is) als een tilde-voorvoegsel
genomen. Als geen van de karakters in het tilde-voorvoegsel zijn
geciteerd, worden de karakters in het tilde-voorvoegsel volgend op de
tilde behandeld als een mogelijke inlog naam. Als deze inlog naam een
nul string is, wordt de tilde vervangen door de waarde van de shell
grootheid HOME. Als HOME ongezet is wordt de thuis directorie van de
gebruiker die de shell draait in plaats daarvan ervoor in de plaats
gezet.
Als het tilde-voorvoegsel een ‘~+’ is, vervangt de waarde van shell
variabele PWD het tilde-voorvoegsel. Als het tilde-voorvoegsel een
‘~-’ is, wordt de waarde van de shell variabele OLDPWD, als gezet,
ervoor in de plaats gezet. Als de karakters volgend op de tilde in het
tilde-voorvoegsel bestaat uit een nummer N, eventueel voorafgegaan door
een ‘+’ of een ‘-’, dan wordt het tilde-voorvoegsel vervangen met het
overeenkomende element van de directorie stapel, zoals zou worden
weergegeven door de directories ingebouwde aangeroepen met het tilde-
voorvoegsel als een argument. builtin invoked with the tilde-prefix as
an argument.
Als de inlog naam ongeldig is, of als de tilde expandering faalt, bli‐
jft het woord onveranderd.
Elke variabele toekenning wordt getest voor ongeciteerde tilde-voor‐
voegsels onmiddellijk volgend op een : of =. In deze gevallen wordt
tilde expandering ook uitgevoerd. Dientengevolge kan men bestandnamen
gebruiken met tildes in toekenningen aan PATH, MAILPATH, en CDPATH, en
de shell kent de geëxpandeerde waarde toe.
Grootheid Expandering
Het ‘$’ karakter introduceert grootheid expandering, opdracht substitu‐
tie, of rekenkundige expandering. De grootheid naam of symbool dat
geëxpandeerd zal worden mag omsloten worden door haakjes, die niet zijn
vereist maar dienen om de variabele te beschermen tegen expanderen met
karakters die er onmiddellijk op volgen en geïnterpreteerd zouden wor‐
den als deel van de naam.
Wanneer haakjes worden gebruikt is het passende afsluitende haakje de
eerste ‘}’ die niet ge-escape’t is door een backslash of binnen een
geciteerd string staat, en niet binnenin een ingebedde rekenkundige
expandering, opdracht substitutie of grootheid expandering.
${grootheid}
De waarde van grootheid wordt vervangen. De haakjes zijn nodig
wanneer de grootheid een plaatsbepaalde grootheid is met meer
dan één cijfer, of wanneer grootheid gevolgd wordt door een
karakter die niet geïnterpreteerd moet worden als deel van de
naam.
Als het eerste karakter van grootheid een uitroepteken is dan wordt een
niveau van variabele omleiden geïntroduceerd. Bash gebruikt de waarde
gevormd van de rest van grootheid als de naam van een variabele; deze
variabele wordt dan geëxpandeerd en die waarde gebruikt in de rest van
de substitutie, in plaats van de waarde van grootheid zelf. Dit status
bekend als indirecte expandering.
In elk van de gevallen onder, woord is voorwerp voor tilde expandering,
grootheid expandering, opdracht substitutie en rekenkundige expander‐
ing. Wanneer geen sub-string expandering wordt uitgevoerd test bash
voor een grootheid die niet is gezet of nul is; de dubbelepunt resul‐
taten alleen weglatend in een test voor een ongezette grootheid.
${grootheid:-woord}
Gebruik Door-val Waardes. Als grootheid is ongezet of nul, de
expandering van woord wordt er dan voor in de plaats gezet.
Anders wordt de waarde van grootheid ervoor in de plaats gezet.
${grootheid:=woord}
Ken Door-val Waardes Toe. Als grootheid ongezet of nul is,
wordt de expandering van woord toegekend aan grootheid. De
waarde van grootheid wordt er dan voor in de plaats gezet. Aan
plaatsbepaalde grootheden en bijzondere grootheden mag niet wor‐
den toegekend op deze manier.
${grootheid:?woord}
Weergave Fout als Nul of Ongezet. Als grootheid nul of ongezet
is wordt de expandering van woord (of een bericht van die
strekking als woord niet aanwezig is) geschreven naar de stan‐
daard fout-uitvoer van de shell en de shell, als die niet
interactief is, eindigt. Anders wordt de waarde van grootheid
ervoor in de plaats gezet.
${grootheid:+woord}
Gebruik Andere Waarde. Als grootheid nul is of ongezet, wordt
niets in de plaats gezet, anders wordt de expandering van woord
ervoor in de plaats gezet.
${grootheid:vanaf}
${grootheid:vanaf:lengte}
Sub-string Expandering. Expandeert tot aan lengte karakters van
grootheid, startend bij de karakters opgegeven door vanaf. Als
lengte weggelaten wordt, geëxpandeerd het tot het sub-string van
If length is omitted, expands to the substring of grootheid,
startend bij het karakter opgegeven door vanaf. lengte and
vanaf zijn rekenkundige expressies (zie REKENKUNDIGE BEOORDELING
onder). lengte moet oplossen in een getal groter dan of gelijk
aan nul. Als vanaf oplost tot een getal kleiner dan nul wordt
de waarde gebruikt als een vanaf-waarde vanaf het einde van de
waarde van grootheid. Als grootheid, @ is, levert dat lengte
plaatsbepaalde grootheden beginnend bij vanaf. Als grootheid
een tabel naam is ge-index’t door @ of *, levert dat de lengte
leden van de tabel beginnend bij ${grootheid[vanaf]}. Sub-string
indexen zijn nul gebaseerd tenzij plaatsbepaalde grootheden wor‐
den gebruikt, in welk geval het indexen start bij 1.
${#parameter}
De lengte in karakters van de waarde van grootheid wordt hier‐
voor in de plaats gezet. Als grootheid * of @ is, is de waarde
die ervoor in de plaats gezet wordt het aantal plaatsbepaalde
grootheden. Als grootheid een tabel naam met index * of @ is,
wordt de ervoor in de plaats gezette waarde het aantal elementen
in de tabel.
${grootheid#woord}
${grootheid##woord}
Het woord wordt geëxpandeerd een patroon opleverend net als bij
padnaam expandering. Als het patroon past op het begin van de
waarde van grootheid, dan levert de expandering de geëxpandeerde
waarde van grootheid met het kortste passende patroon (het ‘‘#’’
geval) of het langste passende patroon (het ‘‘##’’geval)
geschrapt. Als grootheid @ of * is, wordt het patroon verwi‐
jderen om de beurt toegepast op elke plaatsbepaalde patroon, en
de expandering is de opgeleverde lijst. Als grootheid een tabel
variabele is ge-index’t met @ of *, dan wordt het patroon verwi‐
jderen om de beurt toegepast op elk lid van de tabel, en de
expandering is de opgeleverde lijst.
${grootheid%woord}
${grootheid%%woord}
Het woord wordt geëxpandeerd om een patroon te leveren net als
in padnaam expandering. Als het patroon een achteraan hangend
deel van de geëxpandeerde waarde van grootheid past, dan levert
de expandering de geëxpandeerde waarde van grootheid met het
kortste passende patroon (het ‘‘%’’ geval) of het langste
passende patroon (het ‘‘%%’’ geval) geschrapt. Als grootheid @
of * is, wordt het patroon verwijderen toegepast op elke plaats‐
bepaalde grootheid om de beurt, en de expandering is de
opgeleverde lijst. Als grootheid een tabel variabele ge-index’t
met @ of * is, het patroon verwijderen wordt op elk lid
toegepast van de tabel om de beurt, en de expandering is de
opgeleverde lijst.
${grootheid/patroon/string}
${grootheid//patroon/string}
Het patroon wordt geëxpandeerd om een patroon te produceren net
als in padnaam expandering. Grootheid wordt geëxpandeerd en de
langste overeenkomst van patroon met zijn waarde wordt vervangen
met string In de eerste vorm, wordt alleen de eerste
overeenkomst vervangen. De tweede vorm zorgt dat alle
overeenkomsten van patroon worden vervangen met string. Als
patroon begint met #, moet het passen bij het begin van de
geëxpandeerde waarde van grootheid. Als patroon start met %,
moet het passen bij het eind van de geëxpandeerde waarde van
grootheid. Als string nul is, worden overeenkomsten van patroon
geschrapt en de / volgend op patroon mag weggelaten worden. Als
grootheid @ of * is, wordt het vervangen toegepast op elke
plaatsbepaalde grootheid om de beurt, en de expandering is de
opgeleverde lijst. Als grootheid een tabel variabele ge-index’t
met @ of * is, wordt het vervangen toegepast op elk lid van de
tabel om de beurt, en de expandering is de opgeleverde lijst.
Opdracht Vervanging
Opdracht Vervanging laat toe dat de uitvoer van een opdracht de
opdracht-naam vervangt. Er zijn twee vormen:
$(opdracht)
of
opdracht
Bash verricht de expandering door opdracht uit te voeren en de
opdracht-substitutie te vervangen door de standaard uitvoer van de
opdracht, met mogelijke achter-hangende nieuweregels geschrapt.
Ingebedde nieuweregels worden niet geschrapt, maar ze kunnen verwijderd
worden gedurende woord splitsen. De opdracht substitutie $(cat
bestand) kan vervangen worden door het gelijk werkende maar snellere
$(< bestand).
Wanneer de oude stijl terug-aanhalingsteken {#‘#} wordt gebruikt behoud
een backslash {#.BR $ , , of \. De eerste backslash niet voorafgaand
door een backslash beëindigd de opdracht substitutie. Wanneer de
$(opdracht) vorm wordt gebruikt, horen alle karakters tussen de haakjes
bij de opdracht; geen worden bijzonder behandeld.
Opdracht substitutie mag genest worden. Nesten met het terug-aanhaling‐
steken werkt door de binnenste terug-aanhalingstekens het backslashes
uit te vluchten.
Als de substitutie verschijnt binnen dubbele aanhalingstekens wordt
woord-splitsen en padnaam expandering niet uitgevoerd op de resultaten.
Rekenkundige Expandering
Rekenkundige expandering status de oplossing van een rekenkundige
expressie en het ervoor in de plaats zetten van het resultaat toe. D
vorm voor rekenkundige expandering is:
$((expressie))
De expressie wordt behandeld alsof het binnen dubbele aanhalingstekens
verscheen, maar een dubbel aanhalingsteken {#"#} binnen haakjes wordt
niet bijzonder behandeld. Alle zaken in de expandering ondergaan
grootheid expandering, string expandering, opdracht substitutie en aan‐
halingsteken verwijdering. Rekenkundige substituties mogen genest wor‐
den
De oplossing wordt gedaan volgens de regels onder opgesomd bij
REKENKUNDIGE OPLOSSING. Als expressie ongeldig is drukt bash een
bericht af dat de fout aangeeft, en geen substitutie treed op.
Proces Vervanging
Proces substitutie wordt ondersteunt op systemen die benoemde pijpen
ondersteunen (FIFOs) of de /dev/fd methode voor het benoemen van open
bestanden. Het neemt de vorm <(lijst) of >(lijst). Het proces lijst
wordt gedraaid met zijn invoer of uitvoer verbonden met een FIFO of met
een of ander bestand in /dev/fd. De naam van dit bestand wordt
doorgegeven als een argument aan de huidige opdracht als het resultaat
van de expandering. Als de >(lijst) vorm wordt gebruikt zal schrijven
naar het bestand invoer voor lijst leveren. Als de <(lijst) vorm wordt
gebruikt zal het doorgegeven bestand gelezen moeten worden om de
uitvoer van lijst te verkrijgen.
Wanneer beschikbaar, wordt proces substitutie gedaan gelijktijdig met
grootheid en variabele expandering, opdracht substitutie, en
rekenkundige substitutie.
Woord Splitsen
De shell onderzoekt het resultaat van grootheid expandering, opdracht
substitutie, en rekenkundige expandering die niet optrad binnen dubbele
aanhalingstekens voor woord splitsen.
De shell behandeld elk karakter van IFS als een begrenser, en deelt de
resultaten van de andere expanderingen in woorden met deze karakters.
Als IFS ongezet is, of als zijn waarde precies <spatie><tabu
latie><nieuweregel> is, de standaard, dan dient elke opeenvolging van
IFS karakters om woorden te begrenzen. Als IFS een andere waarde dan de
standaard heeft, dan worden opeenvolgingen van de witruimte karakters
spatie en tabulatie genegeerd bij het begin en einde van het woord,
zolang als het witte ruimte karakter in de waarde van IFS is (een IFS
witruimte karakter). Elk karakter in IFS dat niet IFS witruimte is,
samen met elk aangrenzend IFS witruimte karakter, begrensd een veld.
Een opeenvolging van IFS witruimte karakters wordt ook behandeld als
een begrenser. Als de waarde van IFS nul is treed geen woord splitsen
op.
Expliciete nul argumenten ("" of ) blijven behouden. Ongeciteerde
impliciete nul argumenten resulterend van de expandering van grootheden
die geen waardes hebben worden verwijderd. Als een grootheid met geen
waarde wordt geëxpandeerd binnen dubbele aanhalings tekens blijft een
nul argument behouden.
Merk op dat als geen expandering optreed, geen splitsen uitgevoerd
wordt.
padnaam splitsen
Na woord splitsen, tenzij de -f optie gezet is, onderzoekt bash elk
woord op de karakters *, ?, (, en [. Als een van deze karakters
voorkomt dan wordt het woord beschouwd als een regarded as a patroon,
en vervangen met de alphabetisch gesorteerde lijst van bestandnamen die
het patroon passen. Als geen overeenkomstige bestandnamen zijn gevon‐
den, en de shell optie nullglob uit status blijft het woord onveran‐
derd. Als de nullglob optie gezet is, en geen overeenkomsten zijn
gevonden, wordt het woord verwijderd. Als de shell optie nocaseglob
aan status wordt de passing uitgevoerd zonder acht te slaan op het ver‐
schil tussen hoofd- en kleine- letters. Wanneer een patroon wordt
gebruikt voor padnaam expandering moet het karakter . bij het
begin van een naam of onmiddellijk volgend op een slash {#/#} expliciet
passen, tenzij de shell optie dotglob gezet is. Bij passen op een pad‐
naam moet het slash karakter altijd expliciet passen. In andere
gevallen wordt het . karakter niet bijzonder behandeld. Zie de
beschrijving van shopt onder bij SCHELP INGEBOUWDE OPDRACHTEN voor een
beschrijving van de nocaseglob, nullglob, en dotglob shell opties.
De GLOBIGNORE shell variabele mag gebruikt worden om set bestandnamen
die gepast worden met een patroon te beperken. Als GLOBIGNORE gezet
wordt wordt elke passende die ook past op één van de patronen in GLO
BIGNORE verwijderd uit de lijst van overeenkomsten. De bestand namen
. en .. worden altijd genegeerd, zelfs wanneer GLOBIGNORE
gezet is. Echter, het zetten van GLOBIGNORE heeft de werking dat het de
dotglob shell optie aan zet, dus alle andere bestandnamen die beginnen
met een . zullen passen. Om het oude gedrag van het negeren van
bestandnamen beginnend met een . , weer te verkrijgen, maak .*
één van de patronen in GLOBIGNORE. De dotglob optie wordt uitgezet
wanneer GLOBIGNORE ongezet is.
Patroon Passen
Elk karakter dat opduikt in een patroon, anders dan de bijzondere
patroon karakters beschreven onder, passen zichzelf. Het NUL karakter
mag niet voorkomen in een patroon. De bijzondere patroon karakters
moeten geciteerd worden als ze zichzelf letterlijk moeten passen.
De bijzondere karakters hebben de volgende betekenis:
* Past elk string, ook het nul string.
? Past elk enkel karakter
[...] Past elk van de omsloten karakters. Twee karakters gescheiden
door een min {#-#} teken betekend een interval; elk karakter
volgens het woordenboek tussen deze twee karakters, inclusief,
wordt gepast. Als het eerste karakter volgend op de [ een ! of
een ^ is dan elk karakter niet omsloten wordt gepast. Een - mag
gepast worden door het bij te voegen als het eerste of laatste
karakter in de set. Een ] mag gepast worden door het bij te
voegen als het eerste karakter in de set.
Binnen [ en ], kunnen karakter classes opgegeven worden met de
spelling: [:klasse:], waar klasse één van de volgende classes
is, bepaalt in de POSIX.2 standaard:
alnum alpha ascii blank cntrl digit graph lower print punct
space upper xdigit
Een karakter klasse past elk karakter dat bij de klasse hoort.
Binnen [ en ], kan een gelijke klasse opgegeven worden met de
spelling [=c=], dat alle karakters past met hetzelfde collatie-
gewicht (zoals bepaald door de huidige localiteit) als het
karakter c.
Binnen [ en ], past [.symbool.] het collatiesymbool symbool.
Als de extglob shell optie aan status via de shopt ingebouwde, worden
meerdere uitgebreide patroon passing operatoren herkend. In de vol‐
gende beschrijving, is een patroon-lijst een lijst van één of meer
patronen gescheiden door een |. Gecompileerde patronen mogen gevormd
worden met één of meer van de volgende sub-patronen:
?(patronen-lijst)
Past nul of één optreding van het gegeven patronen.
*(patroon-lijst)
Past nul of meerdere optredingen van de gegeven patronen.
+(patroon-lijst)
Past één of meerdere optredingen van het gegeven patroon.
@(patroon-lijst)
Past precies één van de gegeven patronen
!(patroon-lijst)
Past wat dan ook behalve het gegeven patroon
Aanhalings Verwijdering
Na de voorgaande expandering worden alle ongeciteerde optredingen van
de karakters \, , en " die niet resulteerden van één van de boven‐
staande expanderingen verwijderd.
HERRICHTING
Vóór een opdracht wordt uitgevoerd wordt mag zijn invoer en uitvoer
omgeleid worden met een bijzondere notatie, geïnterpreteerd door de
shell. Omleiden mag ook gebruikt worden om bestanden te openen en
sluiten voor de huidige shell uitvoering omgeving. De volgende omleid‐
ing operatoren mogen voorgaan aan, of overal binnen een simpele
opdracht verschijnen, of mag de opdracht volgen. Omleidingen worden
verwerkt in de volgorde waarin ze verschijnen, van links naar rechts.
In de volgende beschrijvingen, als het bestandindicator nummer wordt
weggelaten, en het eerste karakter van de omleiding operator < is, dan
verwijst de omleiding naar de standaard invoer (bestand indicator 0).
Als het eerste karakter van de omleiding operator > is, dan verwijst de
omleiding naar de standaard uitvoer (bestand indicator 1).
Het woord volgend op de omleiding operator in de volgende beschrijvin‐
gen, tenzij anders vermeld, is voorwerp voor haakjes expandering, tilde
expandering, grootheid expandering, opdracht substitutie, rekenkundige
expandering, aanhalingsteken expandering, en padnaam expandering. Als
het geëxpandeerd tot meer dan één woord rapporteert bash een fout.
Merk op dat de volgorde van omleidingen belangrijk is. Bijvoorbeeld de
opdracht:
ls > dirlijst 2>&1
richt standaard uitvoer en standaard fout uitvoer allebei naar het
bestand directorie-lijst, terwijl de opdracht
ls 2>&1 > directorie-lijst
alleen de standaard uitvoer naar bestand directorie-lijst verwijst,
omdat de standaard fout uitvoer werd kopieert als standaard uitvoer
vóór de standaard uitvoer omgeleid was naar because the standard error
was duplicated as standard output before the standard output was redi‐
rected to directorie-lijst.
Een falen in het openen of maken van een bestand zorgt dat het omleiden
faalt.
Omleiden Invoer
Omleiding van invoer zorgt dat een bestand wiens naam resulteerde van
de expandering van woord wordt geopend voor lezen met bestandindicator
n, of de standaard invoer (bestand indicator 0) als n niet is
opgegeven.
De algemene vorm voor omleiden van invoer is:
[n]<woord
Omleiden Uitvoer
Omleiden van uitvoer zorgt dat het bestand wiens naam resulteert van de
expandering van woord wordt geopend voor schrijven met bestandindicator
n, of de standaard uitvoer (bestand indicator 1) als n niet is
opgegeven. Al het bestand niet bestaat wordt het gemaakt; als het
bestaat wordt het afgehakt tot grootte nul.
De algemene vorm voor omleiden van uitvoer is:
[n]>woord
Als de omleiden operator > is, en de noclobber optie voor de set inge‐
bouwde aangezet is zal het omleiden falen als de bestandnaam wiens naam
resulteerde van het expanderen van woord bestaat en een normaal bestand
is. Als de omleiding operator >| is, of de omleiding operator is > en
de noclobber optie voor de set ingebouwde opdracht niet aan staat, dan
zal het omleiden gepoogd worden, zelfs als het bestand genaamd woord
bestaat.
Toevoegen Omgeleide Uitvoer
Omleiden van uitvoer op deze manier zorgt dat het bestand wiens naam
resulteerde van de expandering van woord wordt geopend voor toevoeging
met bestand indicator n, of de standaard uitvoer (bestand indicator 1)
als n niet werd opgegeven. Als het bestand niet bestaat wordt het
gemaakt.
De algemene vorm voor toevoegen van uitvoer is:
[n]>>woord
Omleiding Standaard Uitvoer en Standaard Fouten
Bash laat toe dat de standaard uitvoer (bestand indicator 1) en de
standaard fouten uitvoer (bestand indicator 2) allebei worden omgeleid
naar het bestand wiens naam de expandering van woord is, met dit
bouwsel.
Er zijn twee vormen voor omleiden van standaard uitvoer en standaard
fouten:
&>woord
en
>&woord
Van de twee vormen heeft de eerste de voorkeur. Dit is qua betekenis
gelijk aan
>woord 2>&1
Hier Documenten
Dit soort omleiding draagt de shell op om de invoer te lezen van de
huidige bron totdat een regel die alleen wordt (zonder aanhangende
witruimte) bevat wordt gezien. Alle regel gelezen tot aan dat punt wor‐
den dan gebruikt als de standaard invoer voor een opdracht.
De vorm van hier-documenten is als volgt:
<<[-]woord
hier-document
begrenser
Geen grootheid expandering, opdracht substitutie, padnaam expandering,
of rekenkundige expandering wordt uitgevoerd op woord. Als enig(e)
karakter(s) in woord wordt geciteerd, is de begrenser het resultaat van
de citerings verwijdering op woord, en de regels in het hier-document
worden niet geëxpandeerd. If woord ongeciteerd is worden alle regels
in het hier-document voorwerp voor grootheid expandering, opdracht sub‐
stitutie, en rekenkundige expandering. In het laatste geval wordt
\<nieuwe regel> genegeerd en moet \ gebruikt worden om de karakters te
citeren \, $, en .
Als de omleiding operator <<-, is, dan worden alle voorafgaande tabu‐
latie karakters verwijderd van invoer regels en de regel die begrenzing
bevat. Dit laat toe dat hier-documenten binnen shell scripts kunnen
worden ingesprongen op een natuurlijke manier.
Kopi ren Bestandsindicators
De omleiding operator
[n]<&woord
wordt gebruikt om invoer bestandsindicators te kopiëren. Als woord
geëxpandeerd tot één of meer cijfers wordt de bestandsindicator
opgegeven met n een kopie van die bestandsindicator. Als de cijfers in
woord niet een bestand indicator beschrijven die open is voor invoer,
dan treed een omleiding fout op. Als woord oplost in -, wordt bestand
indicator n gesloten. Als n niet is opgegeven wordt de standaard invoer
(bestand indicator 0) gebruikt.
De operator
[n]>&woord
wordt gelijksoortig gebruikt om uitvoer bestandindicator te kopiëren.
Als n niet is opgegeven wordt de standaard uitvoer (bestand indicator
1) gebruikt. Als de cijfers in woord niet een bestand indicator
opgeven die open is voor invoer treed een omleiding fout op. Een spe‐
ciaal geval is als n wordt weggelaten, en woord niet geëxpandeerd tot
één of meer cijfers wordt de standaard uitvoer en standaard fouten
omgeleid als hiervoor beschreven.
Openen Bestandsindicatoren Voor Lezen en Schrijven
De omleiding operator
[n]<>woord
zorgt dat het bestand wiens naam de expandering van woord is, wordt
geopend voor lezen en schrijven op bestand indicators n, of op bestand
indicator 0 als n niet is opgegeven. Als het bestand niet bestaat wordt
het gemaakt.
ALIASEN
Aliasen laten een string toe om vervangen te worden door een woord wan‐
neer het gebruikt wordt als het eerste woord van een simpele opdracht.
De shell houdt een lijst van aliasen bij die gezet en ontzet mogen wor‐
den met de alias en unalias ingebouwde opdrachten (zie SCHELP INGE
BOUWDE OPDRACHTEN onder). Het eerste woord van elke opdracht, als
ongeciteerd, wordt getest om te zien of het een alias heeft. Als dat
het geval is wordt het woord vervangen door de tekst van de alias. D
alias naam en de vervangende tekst mogen alle geldige shell invoer
bevatten, ook de metakarakters boven opgenoemd, met de uitzondering dat
de alias naam geen = mag hebben. Het eerste woord van de vervangende
tekst wordt getest op aliasen, maar een woord dat gelijk is aan een
alias dat geëxpandeerd wordt, wordt niet nog een keer geëxpandeerd. Dit
betekend dat je ls naar ls -F, mag aliassen bijvoorbeeld, en bash
probeert niet om de vervangende tekst herhaaldelijk te expanderen. Als
het laatste karakter van de alias waarde een lege-ruimte {#blank#} is,
dan wordt het volgende opdracht woord wordt ook getest voor alias
expandering.
Aliassen worden gemaakt en opgesomd met de alias opdracht, en verwi‐
jderd met de unalias opdracht.
Er is geen mechanisme voor het gebruiken van argumenten in de vervan‐
gende text. Als argumenten nodig zijn moet een shell functie worden
gebruikt.
Aliassen worden niet geëxpandeerd wanneer de shell niet interactief is,
tenzij de expand_aliases shell optie is gezet met shopt (zie de
beschrijving voor shopt onder SCHELP INGEBOUWDE OPDRACHTEN onder).
Di regels met betrekking tot het gebruik en definitie van aliassen zijn
soms wat verwarrend. Bash leest altijd tenminste één hele regel invoer
vóór het uitvoeren van de opdrachten op die regel. Aliassen worden
geëxpandeerd wanneer een opdracht gelezen wordt, niet wanneer het wordt
uitgevoerd. Daarom heeft een alias definitie die verschijnt op dezelfde
regel als een andere opdracht geen gelding totdat de volgende regel
invoer gelezen wordt. De opdrachten volgend op de alias definitie op
die regel worden niet beïnvloed door het nieuwe alias. Dit gedrag is
ook een kwestie wanneer functies worden uitgevoerd. Aliassen worden
geëxpandeerd wanneer een functie definitie wordt gelezen, niet wanneer
de functie wordt uitgevoerd omdat een functie definitie zelf een gecom‐
pileerde opdracht is. Als gevolg daarvan zijn aliasen die gedefinieerd
zijn in een functie niet beschikbaar tot na die functie is uitgevoerd.
Om veilig te zijn, zet alias definities op een afzonderlijke regel, en
gebruik alias niet in gecompileerde {#compound#} opdrachten.
Voor bijna elk doel worden aliassen overstegen door shell functies.
FUNCTIES
Een shell functie, gedefinieerd zoals beschreven boven onder SCHELP
SPELLING, bewaard een serie opdrachten voor latere uitvoering. Func‐
ties worden uitgevoerd in de context van de huidige shell; geen nieuw
proces wordt gemaakt om ze uit te leggen (in tegenstelling tot de
uitvoering van een shell script {#script#}). Wanneer een functie wordt
uitgevoerd, worden de argumenten voor de functie de plaatsbepaalde
parameters gedurende zijn uitvoering. De speciale grootheid # wordt
bijgewerkt om de verandering weer te geven. Plaatsbepaalde grootheid 0
blijft onveranderd. Alle andere aspecten van de shell’s uitvoering
omgeving blijven gelijk tussen een functie en zijn aanroeper met de
uitzondering dat de DEBUG val (zie de beschrijving van de trap inge‐
bouwde onder SCHELP INGEBOUWDE OPDRACHTEN onder) niet wordt geërfd.
Variabelen locaal voor de functie mogen bekend gemaakt worden met de
local ingebouwde opdracht. Normaal gesproken worden variabelen en hun
waardes gedeeld tussen de functie en zijn aanroeper.
Als de ingebouwde opdracht return uitgevoerd wordt in een functie, dan
eindigt de functie en uitvoering hervat met de volgende opdracht na de
functie aanroep. Wanneer een functie eindigt worden de plaatsbepaalde
grootheden en de bijzondere grootheid # hersteld tot de waardes die ze
hadden vóór de functies uitvoering.
Functie namen en definities mogen opgesomd met de -f optie voor de
declare of typeset ingebouwde opdrachten. De -F optie voor declare of
typeset zal alleen de functie namen opsommen. Functies mogen ge-expor‐
teerd worden zodat sub-shell’s ze automatisch gedefinieerd hebben met
de -f optie voor de export ingebouwde.
Functies mogen herhaaldelijk {#recursive#} zijn. Geen grens wordt
afgedwongen op het aantal herhaaldelijke aanroepen.
De shell laat rekenkundige expressies toe om opgelost te worden onder
zekere omstandigheden (zie de let ingebouwde opdracht en Rekenkundige
Expandering). Oplossing wordt gedaan in lange hele getallen {#long
integers#} zonder test op overloop, alhoewel delen door 0 gevangen
wordt en gemerkt als fout. De volgende lijst van operators wordt
gegroept in niveaus van gelijke voorrang operators. De niveaus worden
opgesomd in volgorde van aflopende voorrang.
- + enkele min en plus
! ~ logische en bitsgewijze niet
** machtsverheffen
* / % vermenigvuldigen, delen, rest
+ - optellen, aftrekken
<< >> links en rechts bitsgewijze verschuivingen
<= >= < >
vergelijking
== != gelijkheid en ongelijkheid
& bitsgewijze EN
^ bitsgewijze uitsluitende OF {#excl.#}
| bitsgewijze OF
&& logische EN
|| logische OF
expr?expr:expr
voorwaardelijke beoordeling
= *= /= %= += -= <<= >>= &= ^= |=
toekenning
Shell’s variabelen worden toegestaan als operanden; grootheid expander‐
ing wordt uitgevoerd vóór de expressie wordt opgelost. De waarde van
een grootheid wordt omgezet naar een lang heel getal binnen een
expressie. Een shell variabele hoeft zijn heel-getal eigenschap niet
aan te hebben staan om gebruikt te worden in een expressie.
Constanten {#constants#} met een voorlopende 0 worden al octale nummers
geïnterpreteerd. Een voorlopende 0x of 0X betekend hexadecimaal.
Verder hebben getallen de vorm [basis#]n, waar basis een decimaal getal
groter dan 1 en kleiner dan 65 is, de rekenkundige basis voorstellend,
en n is een nummer in die basis. Als basis wordt weggelaten wordt 10
aangenomen. De cijfers groter dan 9 worden voorgesteld door de kleine
letters, hoofdletters, _, en @, in die volgorde. Als basis minder dan
of gelijk is aan 36 mogen kleine en hoofdletters uitwisselbaar worden
gebruikt om cijfers tussen 10 en 35 voor te stellen.
Operatoren worden beoordeeld in volgorde van voorrang. Sub-expressies
in haakjes worden eerst opgelost en mogen de bovenstaande voor‐
rangsregel opzij zetten.
Voorwaardelijke expressies worden gebruikt bij de [[ gecompileerde
opdracht en de test en [ ingebouwde opdrachten om een bestand eigen‐
schap te testen en string en rekenkundige vergelijkingen uit te voeren.
Expressies worden gevormd door de volgende enkele of binaire zaken.
Als enig bestand argument voor één van de zaken van de vorm /dev/fd/n
is, dan wordt bestand indicator n getest.
-a bestand
Waar als bestand bestaat.
-b bestand
Waar als bestand bestaat en een blok speciaal bestand is.
-c bestand
Waar als bestand bestaat en een karakter bijzonder bestand is.
-d bestand
Waar als bestand bestaat en een directorie is.
-e bestand
Waar als bestand bestaat
-f bestand
Waar als bestand bestaat en een normaal bestand is.
-g bestand
Waar als bestand bestaat en zet-groep-id is.
-h bestand
Waar als bestand bestaat en een symbolische koppeling is.
-k bestand
Waar als bestand bestaat en zijn ‘‘sticky’’ bit gezet is.
-p bestand
Waar als bestand bestaat en een benoemde pijp is (FIFO).
-r bestand
Waar als bestand bestaat en leesbaar is.
-s bestand
Waar als bestand bestaat en een grootte groter dan nul heeft.
-t bi Waar als bestand indicator bi open is en naar een terminal
{#terminal#} verwijst.
-u bestand
Waar als bestand bestaat en zijn zet-gebruiker-id is gezet.
-w bestand
Waar als bestand bestaat en schrijfbaar is.
-x bestand
Waar als bestand bestaat en uitvoerbaar is.
-O bestand
Waar als bestand bestaat en in bezit is van het geldende
gebruiker id.
-G bestand
Waar als bestand bestaat en in bezit is van het geldende groep
id.
-L bestand
Waar als bestand bestaat en een symbolische koppeling is.
-S bestand
Waar als bestand bestaat en een socket is.
-N bestand
Waar als bestand bestaat en veranderd is sinds het laatst
gelezen werd.
bestand1 -nt bestand2
Waar als bestand1 nieuwer (volgens aanpassing {#modification#}
datum) dan bestand2.
bestand1 -ot bestand2
Waar als bestand1 ouder dan bestand2 is.
bestand1 -ef bestand2
Waar als bestand1 en bestand2 hetzelfde apparaat en inodenummer
hebben.
-o optienaam
Waar als shell optie optienaam aan status. Zie de lijst van
opties onder de beschrijving van de -o optie voor de set inge‐
bouwde onder.
-z string
Waar als de lengte van string nul is.
-n string
string Waar als de lengte van string ongelijk nul is.
string1 == string2
Waar als de strings gelijk zijn. = mag gebruikt worden in plaats
van ==.
string1 != string2
Waar als de strings niet gelijk zijn.
string1 < string2
Waar als string1 sorteert vóór string2 volgens het woordenboek
van de huidige localiteit.
string1 > string2
Waar als string1 sorteert na string2 volgens het woordenboek van
de huidige localiteit.
arg1 OP arg2
OP is één van -eq, -ne, -lt, -le, -gt, of -ge. Deze
rekenkundige binaire operators geven waar terug als arg1 respec‐
tievelijk gelijk is aan {#-eq#}, niet gelijk is aan {#-ne#},
minder dan {#-lt#}, minder dan of gelijk aan {#-le#}, groter dan
{#-gt#}, of groter dan of gelijk aan {#-ge#} arg2. Arg1 en arg2
mogen positief of negatieve hele getallen zijn.
Wanneer een simpele opdracht wordt uitgevoerd doet de shell de volgende
expanderingen, toekenningen en omleidingen, van links naar rechts.
1. Het woord dat de verwerker aanmerkt voor variabele toekenningen
(zij die voorafgaan aan de opdracht naam) en omleidingen worden
bewaard om later verwerkt te worden.
2. De woorden die niet variabele toekenningen of omleidingen zijn
worden geëxpandeerd. Als enig woord overblijft na expandering,
wordt het eerste woord genomen als de naam van de opdracht en de
overblijvende woorden worden argumenten.
3. Omleidingen worden uitgevoerd zoals boven onder OMLEIDEN
beschreven.
4. De tekst na het = teken in elke variabele toekenning ondergaat
tilde expandering, grootheid expandering, opdracht substitutie,
rekenkundige expandering, en citering verwijdering vóór te wor‐
den toegekend aan de variabele.
Als geen opdracht naam gevonden wordt beïnvloeden variabele toekennin‐
gen de huidige schelp omgeving. Anders worden de variabelen bij de
omgeving van de uitvoerende opdracht gevoegd en beïnvloeden ze de
huidige shell omgeving niet. Als enige van de toekenningen probeert
een waarde toe te kennen aan een alleen-lezen variabele treedt een fout
op, en de opdracht eindigt met een ongelijk-nul status.
Als geen opdracht naam resulteert worden omleidingen gedaan, maar die
beïnvloeden de huidige shell omgeving niet. Een omleiding-fout zorgt
dat de opdracht met een ongelijk-nul status eindigt.
Als er een opdracht naam overblijft na expandering gaat uitvoering
verder zoals onder beschreven. Anders eindigt de opdracht. Als één van
de vergrotingen een opdracht substitutie bevat is de einde status van
de opdracht de einde status van de laatste uitgevoerde opdracht substi‐
tutie. Als er geen opdracht substituties waren eindigt de opdracht met
een nul status.
Nadat een opdracht is gesplitst in woorden, worden de volgende acties
ondernomen als het resulteert in een simpele opdracht en een optionele
lijst argumenten.
Als de opdracht naam geen slashes bevat probeert de shell het te vin‐
den. Als er een shell functie met die naam bestaat, wordt die functie
aangeroepen zoals beschreven boven in FUNCTIES. Als de naam niet
overeenkomt met een functie zoekt de shell in de lijst ingebouwden. Als
een overeenkomst is gevonden wordt die ingebouwde aangeroepen.
Als de naam nóg de naam van een shell functie, nóg de naam van een
ingebouwde is, en geen slashes bevat zoekt bash elk element van PATH
voor een directorie die een uitvoerbaar bestand met die naam bevat.
Bash gebruikt een hash tabel om de volle bestand namen te onthouden van
het uitvoerbare bestand (zie hash onder SHELL INGEBOUWDE OPDRACHTEN
onder). Een volledig doorzoeken van de directories in PATH wordt
alleen gedaan als de opdracht niet gevonden wordt in de hash tabel.
Als het zoeken faalt, drukt de shell een fout bericht af en keert terug
met einde status 127.
Als het zoeken slaagt, of als de opdracht naam één of meer slashes
bevat voert de shell het benoemde programma uit in een afzonderlijke
uitvoering omgeving. Argument 0 wordt gezet naar de gegeven naam, en
de overblijvende argumenten voor de opdracht worden gezet naar de
gegeven argumenten, als aanwezig.
Als deze uitvoering faalt omdat het bestand in niet uitvoerbare vorm
is, en het bestand geen map is, wordt aangenomen dat het een shell
script is; een bestand dat shell opdrachten bevat. Een sub-shell wordt
gejongd om het uit te voeren. Deze sub-shell herinitialiseerd zichzelf,
zodat het effect is alsof een nieuwe shell wordt aangeroepen om het
script af te handelen, met uitzondering dat herinnerde plaatsen van
opdrachten worden herinnerd door de ouder (zie hash onder bij SHELL
INGEBOUWDE OPDRACHTEN) worden behouden door het kind.
Als het programma een bestand is dat begint met #!, specificeert de
rest van de regel een interpreteerder voor het programma. De shell
voert de opgegeven interpreteerder uit op systemen die deze vorm niet
zelf afhandelen. De argumenten voor de interpreteerder bestaan uit een
enkel optioneel argument, volgend op de interpreteerder naam op de
eerste regel van het programma, gevolgd door de naam van het programma,
gevolgd door de opdracht argumenten, als aanwezig.
De shell heeft een uitvoering omgeving, die bestaat uit het volgende:
· open bestanden geërfd door de shell bij aanroepen, aangepast
door omleidingen geleverd door de exec ingebouwde
· de huidige werk directorie zoals gezet door cd, pushd, of popd,
of geërfd door de schelp bij aanroepen
· het bestand maak masker zoals gezet door umask of geërfd van de
shell’s ouder
· huidige ‘traps’ {vallen/valkuilen} gezet door trap
· shell grootheden die gezet zijn door variabele toekenning of met
set of geërfd van de shell’s ouder in de omgeving
· shell functies gedefinieerd gedurende uitvoering of geërfd van
de shell’s ouder in de omgeving
· opties aangezet bij aanroepen (òf wegens standaard gedrag, òf
met opdrachtregel argumenten) of door set gezet.
· opties aangezet door shopt
· shell aliasses bepaalt met alias
· verschillende proces ID’s, onder andere die van achtergrond
taken, de waarde van $$, en de waarde van $PPID
Wanneer een simpele opdracht anders dan een ingebouwde of shell functie
wordt uitgevoerd, wordt het uitgevoerd in een aparte uitvoerings omgev‐
ing die bestaat uit het volgende. Tenzij anders vermeld worden de
waardes geërfd van de shell.
· de shell’s open bestanden, plus enige aanpassingen en aanvullin‐
gen opgegeven door omleidingen voor de opdracht
· de huidige werk directorie
· het bestand maak mode masker
· shell variabelen aangemerkt voor exportatie, samen met variabe‐
len geëxporteerd voor de opdracht, doorgegeven in de omgeving
· ‘traps’ afgevangen door de shell, worden reset tot de waardes
die de shell erfde van zijn ouder, en traps genegeerd door de
shell worden genegeerd
Een opdracht aangeroepen in deze aparte omgeving kan niet de shell’s
uitvoering omgeving beïnvloeden.
Opdracht substitutie en asynchrone opdrachten worden aangeroepen in een
sub-shell omgeving die een kloon is van de shell omgeving, behalve dat
traps gevangen door de shell worden reset tot de waardes die de shell
erfde van zijn ouder bij aanroepen. Ingebouwde opdrachten die worden
aangeroepen als onderdeel van een pijplijn worden ook uitgevoerd in een
sub-shell omgeving. Veranderingen gemaakt voor de sub-shell omgeving
kunnen de shell’s uitvoering omgeving niet beïnvloeden.
OMGEVING
Wanneer een programma wordt aangeroepen, wordt het een tabel met
strings gegeven, bekend onder de naam omgeving. Dit is een lijst van
naam-waarde paren, in de vorm naam=waarde.
De shell laat u toe deze omgeving te manipuleren op verschillende
manieren. Bij aanroepen zoekt de shell zijn eigen omgeving en maakt
een grootheid voor elke gevonden naam, het automatisch aanmerkend voor
exportering naar kind processen. Uitgevoerde opdrachten erven deze
omgeving. De export en declare -x opdrachten laten toe dat grootheden
en functies aan de omgeving kunnen worden toegevoegd of eruit worden
geschrapt. Als de waarde van een grootheid in de omgeving wordt
aangepast wordt de nieuwe waarde onderdeel van de omgeving, de oude
waarde vervangend. De omgeving die geërfd wordt door elke uitvoerende
opdracht {programma} bestaat uit de initiële omgeving van de shell,
waarvan de waardes kunnen zijn aangepast in de shell, zonder de paren
die zijn verwijderd met de. unset opdracht, met mogelijke aanvullingen
met de export en declare -x opdrachten.
De omgeving voor een simpele opdracht of functie kan tijdelijk aange‐
vuld worden door een grootheid toekenning ervoor te zetten, zoals
beschreven bij GROOTHEDEN. Deze toekennings commando’s beïnvloeden
alleen de omgeving die door die opdracht wordt gezien.
Als de -k optie is gezet (zie de set ingebouwde opdracht onder), dan
worden alle grootheid-toekeningen in de omgeving van een opdracht
geplaatst, niet alleen die waaraan het aan de opdracht voorafgaat.
Wanneer bash een externe opdracht aanroept wordt de variabele _ gezet
naar de volledige naam van de opdracht, en wordt die variabele
doorgeven aan die opdracht zijn omgeving.
Voor gebruik door de shell wordt aangenomen dat een opdracht die
eindigt met een nul beeindigings-status geslaagd is. Een beeindigings-
status van nul geeft succes aan. Een niet-nul eindwaarde geeft falen
aan. Wanneer een opdracht eindigt met een fataal signaal gebruikt bash
de waarde 128+0als de eindwaarde.
Als een opdracht niet werd gevonden, geeft het kind-proces dat gemaakt
werd om het uit te voeren 127 terug. Als een opdracht wel werd gevonden
maar niet uitvoerbaar is, is de terugkeer-waarde 126.
Als een opdracht faalt door een fout tijdens het expanderen of het
omleiden is de eindwaarde groten dan nul.
Shell ingebouwde opdrachten geven een waarda van 0 (waar) als succes,
en niet-nul (fout) als een fout optreedt tijdens uitvoering. Alle
ingebouwden keren terug met 2 om verkeerd gebruik aan te geven.
Bash zelf keert terug met de eindwaarde van de laatst uitgevoerde
opdracht, tenzij er een spellingsfout is, in welk geval het eindigt met
een niet-nul terugkeerwaarde. Zie ook de exit ingebouwde opdracht
onder.
SIGNALS
Als bash interactief is negeert het in de afwezigheid van enige vallen
{traps} SIGTERM {zodat kill 0 de interactieve schell niet vermoord), en
SIGINT wordt gevangen en afgehandeld (zodat de wait ingebouwde onder‐
breekbaar is). In elk geval negeert bash SIGQUIT. Als taak controle
werkt, dan negeert bash SIGTTIN, SIGTTOU, en SIGTSTP.
Synchrone taken die zijn gestart door bash hebben signaal behandelaars
die gezet zijn naar waardes die zijn geërfd door de shell van zijn
ouder. Wanneer taak controle niet werkt negeren asynchrone opdrachten
SIGINT en SIGQUIT ook. Opdrachten die draaien tengevolgde van
opdracht-substitutie negeren de toetsenbord-gegenereerde taak-controle
signalen. SIGTTIN, SIGTTOU, en SIGTSTP.
De shell eindigt standaard bij ontvangen van een SIGHUP. Vóór eindigen
zendt het een SIGHUP naar alle taken, draaiende en gestopte. Gestopte
taken wordt een SIGCONT gezonden om er zeker van te zijn dat ze de
SIGHUP ontvangen. Om de shell te behoeden voor het zenden van een sig‐
naal naar een bepaalde taak moet het verwijderd worden van de taken-
tabel met de disown ingebouwde (zie SHELL INGEBOUWDE OPDRACHTEN onder)
of gemarkeerd om geen SIGHUP te ontvangen met disown -h.
Als de huponexit shell optie gezet werdt met shopt, dan zendt bash een
SIGHUP naar alle taken wanneer een interactieve login shell eindigt
Als bash een signaal ontvangt waarvoor een val {trap} is gezet, terwijl
het wacht op het einde van de opdracht, zal de val niet worden uitgevo‐
erd totdat de opdracht eindigt. Als bash wacht op een asynchrone
opdracht met de wait ingebouwde, dan zal het ontvangen van een signaal
waarvoor een val werd gezet zorgen dat de wait ingebouwde onmiddelijk
terugkeert met een terugkeer-waarde groter dan 128, onmiddelijk nadat
de val werd uitgevoerd. ----vertaalt-tot-hier...----
Job control refers to the ability to selectively stop (suspend) the
execution of processes and continue (resume) their execution at a later
point. A user typically employs this facility via an interactive
interface supplied jointly by the system’s terminal driver and bash.
The shell associates a job with each pipeline. It keeps a table of
currently executing jobs, which may be listed with the jobs command.
When bash starts a job asynchronously (in the background), it prints a
line that looks like:
[1] 25647
indicating that this job is job number 1 and that the process ID of the
last process in the pipeline associated with this job is 25647. All of
the processes in a single pipeline are members of the same job. Bash
uses the job abstraction as the basis for job control.
To facilitate the implementation of the user interface to job control,
the system maintains the notion of a current terminal process group ID.
Members of this process group (processes whose process group ID is
equal to the current terminal process group ID) receive keyboard-gener‐
ated signals such as SIGINT. These processes are said to be in the
foreground. Background processes are those whose process group ID dif‐
fers from the terminal’s; such processes are immune to keyboard-gener‐
ated signals. Only foreground processes are allowed to read from or
write to the terminal. Background processes which attempt to read from
(write to) the terminal are sent a SIGTTIN (SIGTTOU) signal by the ter‐
minal driver, which, unless caught, suspends the process.
If the operating system on which bash is running supports job control,
bash allows you to use it. Typing the suspend character (typically ^Z,
Control-Z) while a process is running causes that process to be stopped
and returns you to bash. Typing the delayed suspend character (typi‐
cally ^Y, Control-Y) causes the process to be stopped when it attempts
to read input from the terminal, and control to be returned to bash.
The user may then manipulate the state of this job, using the bg com‐
mand to continue it in the background, the fg command to continue it in
the foreground, or the kill command to kill it. A ^Z takes effect
immediately, and has the additional side effect of causing pending out‐
put and typeahead to be discarded.
There are a number of ways to refer to a job in the shell. The charac‐
ter % introduces a job name. Job number n may be referred to as %n. A
job may also be referred to using a prefix of the name used to start
it, or using a substring that appears in its command line. For exam‐
ple, %ce refers to a stopped ce job. If a prefix matches more than one
job, bash reports an error. Using %?ce, on the other hand, refers to
any job containing the string ce in its command line. If the substring
matches more than one job, bash reports an error. The symbols %% and
%+ refer to the shell’s notion of the current job, which is the last
job stopped while it was in the foreground or started in the back‐
ground. The previous job may be referenced using %-. In output per‐
taining to jobs (e.g., the output of the jobs command), the current job
is always flagged with a +, and the previous job with a -.
Simply naming a job can be used to bring it into the foreground: %1 is
a synonym for fg %1 , bringing job 1 from the background into the
foreground. Similarly, %1 & resumes job 1 in the background,
equivalent to bg %1 .
The shell learns immediately whenever a job changes state. Normally,
bash waits until it is about to print a prompt before reporting changes
in a job’s status so as to not interrupt any other output. If the -b
option to the set builtin command is enabled, bash reports such changes
immediately.
If an attempt to exit bash is made while jobs are stopped, the shell
prints a warning message. The jobs command may then be used to inspect
their status. If a second attempt to exit is made without an interven‐
ing command, the shell does not print another warning, and the stopped
jobs are terminated.
PROMPTING
When executing interactively, bash displays the primary prompt PS1 when
it is ready to read a command, and the secondary prompt PS2 when it
needs more input to complete a command. Bash allows these prompt
strings to be customized by inserting a number of backslash-escaped
special characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format (e.g., "Tue May
26")
\e an ASCII escape character (033)
\h the hostname up to the first ‘.’
\H the hostname
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion
following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel (e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn
\\ a backslash
\[ begin a sequence of non-printing characters, which could
be used to embed a terminal control sequence into the
prompt
\] end a sequence of non-printing characters
The command number and the history number are usually different: the
history number of a command is its position in the history list, which
may include commands restored from the history file (see HISTORY
below), while the command number is the position in the sequence of
commands executed during the current shell session. After the string
is decoded, it is expanded via parameter expansion, command substitu‐
tion, arithmetic expansion, string expansion, and quote removal, sub‐
ject to the value of the promptvars shell option (see the description
of the shopt command under SHELL BUILTIN COMMANDS below).
READLINE
This is the library that handles reading input when using an interac‐
tive shell, unless the --noediting option is given at shell invocation.
By default, the line editing commands are similar to those of emacs. A
vi-style line editing interface is also available. To turn off line
editing after the shell is running, use the +o emacs or +o vi options
to the set builtin (see SHELL BUILTIN COMMANDS below).
Readline Notation
In this section, the emacs-style notation is used to denote keystrokes.
Control keys are denoted by C-key, e.g., C-n means Control-N. Simi‐
larly, meta keys are denoted by M-key, so M-x means Meta-X. (On key‐
boards without a meta key, M-x means ESC x, i.e., press the Escape key
then the x key. This makes ESC the meta prefix. The combination M-C-x
means ESC-Control-x, or press the Escape key then hold the Control key
while pressing the x key.)
Readline commands may be given numeric arguments, which normally act as
a repeat count. Sometimes, however, it is the sign of the argument
that is significant. Passing a negative argument to a command that
acts in the forward direction (e.g., kill-line) causes that command to
act in a backward direction. Commands whose behavior with arguments
deviates from this are noted below.
When a command is described as killing text, the text deleted is saved
for possible future retrieval (yanking). The killed text is saved in a
kill ring. Consecutive kills cause the text to be accumulated into one
unit, which can be yanked all at once. Commands which do not kill text
separate the chunks of text on the kill ring.
Readline Initialization
Readline is customized by putting commands in an initialization file
(the inputrc file). The name of this file is taken from the value of
the INPUTRC variable. If that variable is unset, the default is
~/.inputrc. When a program which uses the readline library starts up,
the initialization file is read, and the key bindings and variables are
set. There are only a few basic constructs allowed in the readline
initialization file. Blank lines are ignored. Lines beginning with a
# are comments. Lines beginning with a $ indicate conditional con‐
structs. Other lines denote key bindings and variable settings.
The default key-bindings may be changed with an inputrc file. Other
programs that use this library may add their own commands and bindings.
For example, placing
M-Control-u: universal-argument
or
C-Meta-u: universal-argument
into the inputrc would make M-C-u execute the readline command univer‐
sal-argument.
The following symbolic character names are recognized: RUBOUT, DEL,
ESC, LFD, NEWLINE, RET, RETURN, SPC, SPACE, and TAB. In addition to
command names, readline allows keys to be bound to a string that is
inserted when the key is pressed (a macro).
Readline Key Bindings
The syntax for controlling key bindings in the inputrc file is simple.
All that is required is the name of the command or the text of a macro
and a key sequence to which it should be bound. The name may be speci‐
fied in one of two ways: as a symbolic key name, possibly with Meta- or
Control- prefixes, or as a key sequence. When using the form key
name:function-name or macro, keyname is the name of a key spelled out
in English. For example:
Control-u: universal-argument
Meta-Rubout: backward-kill-word
Control-o: "> output"
In the above example, C-u is bound to the function universal-argument,
M-DEL is bound to the function backward-kill-word, and C-o is bound to
run the macro expressed on the right hand side (that is, to insert the
text > output into the line).
In the second form, "keyseq":function-name or macro, keyseq differs
from keyname above in that strings denoting an entire key sequence may
be specified by placing the sequence within double quotes. Some GNU
Emacs style key escapes can be used, as in the following example.
"\C-u": universal-argument
"\C-x\C-r": re-read-init-file
"\e[11~": "Function Key 1"
In this example, C-u is again bound to the function universal-argument.
C-x C-r is bound to the function re-read-init-file, and ESC [ 1 1 ~ is
bound to insert the text Function Key 1. The full set of GNU Emacs
style escape sequences is
\C- control prefix
\M- meta prefix
\e an escape character
\\ backslash
\" literal "
\ literal ’
In addition to the GNU Emacs style escape sequences, a second set of
backslash escapes is available:
\a alert (bell)
\b backspace
\d delete
\f form feed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
\nnn the character whose ASCII code is the octal value nnn
(one to three digits)
\xnnn the character whose ASCII code is the hexadecimal value
nnn (one to three digits)
When entering the text of a macro, single or double quotes must be used
to indicate a macro definition. Unquoted text is assumed to be a func‐
tion name. In the macro body, the backslash escapes described above
are expanded. Backslash will quote any other character in the macro
text, including " and ’.
Bash allows the current readline key bindings to be displayed or modi‐
fied with the bind builtin command. The editing mode may be switched
during interactive use by using the -o option to the set builtin com‐
mand (see SHELL BUILTIN COMMANDS below).
Readline Variables
Readline has variables that can be used to further customize its behav‐
ior. A variable may be set in the inputrc file with a statement of the
form
set variable-name value
Except where noted, readline variables can take the values On or Off.
The variables and their default values are:
bell-style (audible)
Controls what happens when readline wants to ring the terminal
bell. If set to none, readline never rings the bell. If set to
visible, readline uses a visible bell if one is available. If
set to audible, readline attempts to ring the terminal’s bell.
comment-begin ( # )
The string that is inserted when the readline insert-comment
command is executed. This command is bound to M-# in emacs mode
and to # in vi command mode.
completion-ignore-case (Off)
If set to On, readline performs filename matching and completion
in a case-insensitive fashion.
completion-query-items (100)
This determines when the user is queried about viewing the num‐
ber of possible completions generated by the possible-comple
tions command. It may be set to any integer value greater than
or equal to zero. If the number of possible completions is
greater than or equal to the value of this variable, the user is
asked whether or not he wishes to view them; otherwise they are
simply listed on the terminal.
convert-meta (On)
If set to On, readline will convert characters with the eighth
bit set to an ASCII key sequence by stripping the eighth bit and
prepending an escape character (in effect, using escape as the
meta prefix).
disable-completion (Off)
If set to On, readline will inhibit word completion. Completion
characters will be inserted into the line as if they had been
directorieped to self-insert.
editing-mode (emacs)
Controls whether readline begins with a set of key bindings sim‐
ilar to emacs or vi. editing-mode can be set to either emacs or
vi.
enable-keypad (Off)
When set to On, readline will try to enable the application key‐
pad when it is called. Some systems need this to enable the
arrow keys.
expand-tilde (Off)
If set to on, tilde expansion is performed when readline
attempts word completion.
horizontal-scroll-mode (Off)
When set to On, makes readline use a single line for display,
scrolling the input horizontally on a single screen line when it
becomes longer than the screen width rather than wrapping to a
new line.
input-meta (Off)
If set to On, readline will enable eight-bit input (that is, it
will not strip the high bit from the characters it reads),
regardless of what the terminal claims it can support. The name
meta-flag is a synonym for this variable.
isearch-terminators ( C-[C-J )
The string of characters that should terminate an incremental
search without subsequently executing the character as a com‐
mand. If this variable has not been given a value, the charac‐
ters ESC and C-J will terminate an incremental search.
keydir (emacs)
Set the current readline keydirectorie. The set of valid keydir
names is emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
vi-command, and vi-insert. vi is equivalent to vi-command;
emacs is equivalent to emacs-standard. The default value is
emacs; the value of editing-mode also affects the default keydi‐
rectorie.
mark-directories (On)
If set to On, completed directory names have a slash appended.
mark-modified-lines (Off)
If set to On, history lines that have been modified are dis‐
played with a preceding asterisk (*).
output-meta (Off)
If set to On, readline will display characters with the eighth
bit set directly rather than as a meta-prefixed escape sequence.
print-completions-horizontally (Off)
If set to On, readline will display completions with matches
sorted horizontally in alphabetical order, rather than down the
screen.
show-all-if-ambiguous (Off)
This alters the default behavior of the completion functions.
If set to on, words which have more than one possible completion
cause the matches to be listed immediately instead of ringing
the bell.
visible-stats (Off)
If set to On, a character denoting a file’s type as reported by
stat(2) is appended to the filename when listing possible com‐
pletions.
Readline Conditional Constructs
Readline implements a facility similar in spirit to the conditional
compilation features of the C preprocessor which allows key bindings
and variable settings to be performed as the result of tests. There
are four parser directives used.
$if The $if construct allows bindings to be made based on the edit‐
ing mode, the terminal being used, or the application using
readline. The text of the test extends to the end of the line;
no characters are required to isolate it.
mode The mode= form of the $if directive is used to test
whether readline is in emacs or vi mode. This may be
used in conjunction with the set keydirectorie command,
for instance, to set bindings in the emacs-standard and
emacs-ctlx keydirectories only if readline is starting
out in emacs mode.
term The term= form may be used to include terminal-specific
key bindings, perhaps to bind the key sequences output by
the terminal’s function keys. The word on the right side
of the = is tested against the both full name of the ter‐
minal and the portion of the terminal name before the
first -. This allows sun to match both sun and sun-cmd,
for instance.
application
The application construct is used to include application-
specific settings. Each program using the readline
library sets the application name, and an initialization
file can test for a particular value. This could be used
to bind key sequences to functions useful for a specific
program. For instance, the following command adds a key
sequence that quotes the current or previous word in
Bash:
$if Bash
# Quote the current or previous word
"\C-xq": "\eb\"\ef\""
$endif
$endif This command, as seen in the previous example, terminates an $if
command.
$else Commands in this branch of the $if directive are executed if the
test fails.
$include
This directive takes a single filename as an argument and reads
commands and bindings from that file. For example, the follow‐
ing directive would read /etc/inputrc:
$include /etc/inputrc
Searching
Readline provides commands for searching through the command history
(see HISTORY below) for lines containing a specified string. There are
two search modes: incremental and non-incremental.
Incremental searches begin before the user has finished typing the
search string. As each character of the search string is typed, read‐
line displays the next entry from the history matching the string typed
so far. An incremental search requires only as many characters as
needed to find the desired history entry. The characters present in
the value of the isearch-terminators variable are used to terminate an
incremental search. If that variable has not been assigned a value the
Escape and Control-J characters will terminate an incremental search.
Control-G will abort an incremental search and restore the original
line. When the search is terminated, the history entry containing the
search string becomes the current line. To find other matching entries
in the history list, type Control-S or Control-R as appropriate. This
will search backward or forward in the history for the next entry
matching the search string typed so far. Any other key sequence bound
to a readline command will terminate the search and execute that com‐
mand. For instance, a newline will terminate the search and accept the
line, thereby executing the command from the history list.
Non-incremental searches read the entire search string before starting
to search for matching history lines. The search string may be typed
by the user or be part of the contents of the current line.
Readline Command Names
The following is a list of the names of the commands and the default
key sequences to which they are bound. Command names without an accom‐
panying key sequence are unbound by default.
Commands for Moving
beginning-of-line (C-a)
Move to the start of the current line.
end-of-line (C-e)
Move to the end of the line.
forward-char (C-f)
Move forward a character.
backward-char (C-b)
Move back a character.
forward-word (M-f)
Move forward to the end of the next word. Words are composed of
alphanumeric characters (letters and digits).
backward-word (M-b)
Move back to the start of this, or the previous, word. Words
are composed of alphanumeric characters (letters and digits).
clear-screen (C-l)
Clear the screen leaving the current line at the top of the
screen. With an argument, refresh the current line without
clearing the screen.
redraw-current-line
Refresh the current line.
Commands for Manipulating the History
accept-line (Newline, Return)
Accept the line regardless of where the cursor is. If this line
is non-empty, add it to the history list according to the state
of the HISTCONTROL variable. If the line is a modified history
line, then restore the history line to its original state.
previous-history (C-p)
Fetch the previous command from the history list, moving back in
the list.
next-history (C-n)
Fetch the next command from the history list, moving forward in
the list.
beginning-of-history (M-<)
Move to the first line in the history.
end-of-history (M->)
Move to the end of the input history, i.e., the line currently
being entered.
reverse-search-history (C-r)
Search backward starting at the current line and moving ‘up’
through the history as necessary. This is an incremental
search.
forward-search-history (C-s)
Search forward starting at the current line and moving ‘down’
through the history as necessary. This is an incremental
search.
non-incremental-reverse-search-history (M-p)
Search backward through the history starting at the current line
using a non-incremental search for a string supplied by the
user.
non-incremental-forward-search-history (M-n)
Search forward through the history using a non-incremental
search for a string supplied by the user.
history-search-forward
Search forward through the history for the string of characters
between the start of the current line and the current cursor
position (the point). This is a non-incremental search.
history-search-backward
Search backward through the history for the string of characters
between the start of the current line and the point. This is a
non-incremental search.
yank-nth-arg (M-C-y)
Insert the first argument to the previous command (usually the
second word on the previous line) at point (the current cursor
position). With an argument n, insert the nth word from the
previous command (the words in the previous command begin with
word 0). A negative argument inserts the nth word from the end
of the previous command.
yank-last-arg (M-., M-_)
Insert the last argument to the previous command (the last word
of the previous history entry). With an argument, behave
exactly like yank-nth-arg. Successive calls to yank-last-arg
move back through the history list, inserting the last argument
of each line in turn.
shell-expand-line (M-C-e)
Expand the line as the shell does. This performs alias and his‐
tory expansion as well as all of the shell word expansions. See
HISTORY EXPANSION below for a description of history expansion.
history-expand-line (M-^)
Perform history expansion on the current line. See HISTORY
EXPANSION below for a description of history expansion.
magic-space
Perform history expansion on the current line and insert a
space. See HISTORY EXPANSION below for a description of history
expansion.
alias-expand-line
Perform alias expansion on the current line. See ALIASES above
for a description of alias expansion.
history-and-alias-expand-line
Perform history and alias expansion on the current line.
insert-last-argument (M-., M-_)
A synonym for yank-last-arg.
operate-and-get-next (C-o)
Accept the current line for execution and fetch the next line
relative to the current line from the history for editing. Any
argument is ignored.
Commands for Changing Text
delete-char (C-d)
Delete the character under the cursor. If point is at the
beginning of the line, there are no characters in the line, and
the last character typed was not bound to delete-char, then
return EOF.
backward-delete-char (Rubout)
Delete the character behind the cursor. When given a numeric
argument, save the deleted text on the kill ring.
forward-backward-delete-char
Delete the character under the cursor, unless the cursor is at
the end of the line, in which case the character behind the cur‐
sor is deleted. By default, this is not bound to a key.
quoted-insert (C-q, C-v)
Add the next character typed to the line verbatim. This is how
to insert characters like C-q, for example.
tab-insert (C-v TAB)
Insert a tab character.
self-insert (a, b, A, 1, !, ...)
Insert the character typed.
transpose-chars (C-t)
Drag the character before point forward over the character at
point. Point moves forward as well. If point is at the end of
the line, then transpose the two characters before point. Nega‐
tive arguments don’t work.
transpose-words (M-t)
Drag the word behind the cursor past the word in front of the
cursor moving the cursor over that word as well.
upcase-word (M-u)
Uppercase the current (or following) word. With a negative
argument, uppercase the previous word, but do not move point.
downcase-word (M-l)
Lowercase the current (or following) word. With a negative
argument, lowercase the previous word, but do not move point.
capitalize-word (M-c)
Capitalize the current (or following) word. With a negative
argument, capitalize the previous word, but do not move point.
Killing and Yanking
kill-line (C-k)
Kill the text from the current cursor position to the end of the
line.
backward-kill-line (C-x Rubout)
Kill backward to the beginning of the line.
unix-line-discard (C-u)
Kill backward from point to the beginning of the line. The
killed text is saved on the kill-ring.
kill-whole-line
Kill all characters on the current line, no matter where the
cursor is.
kill-word (M-d)
Kill from the cursor to the end of the current word, or if
between words, to the end of the next word. Word boundaries are
the same as those used by forward-word.
backward-kill-word (M-Rubout)
Kill the word behind the cursor. Word boundaries are the same
as those used by backward-word.
unix-word-rubout (C-w)
Kill the word behind the cursor, using white space as a word
boundary. The word boundaries are different from back
ward-kill-word.
delete-horizontal-space (M-\)
Delete all spaces and tabs around point.
kill-region
Kill the text between the point and mark (saved cursor posi‐
tion). This text is referred to as the region.
copy-region-as-kill
Copy the text in the region to the kill buffer.
copy-backward-word
Copy the word before point to the kill buffer. The word bound‐
aries are the same as backward-word.
copy-forward-word
Copy the word following point to the kill buffer. The word
boundaries are the same as forward-word.
yank (C-y)
Yank the top of the kill ring into the buffer at the cursor.
yank-pop (M-y)
Rotate the kill ring, and yank the new top. Only works follow‐
ing yank or yank-pop.
Numeric Arguments
digit-argument (M-0, M-1, ..., M--)
Add this digit to the argument already accumulating, or start a
new argument. M-- starts a negative argument.
universal-argument
This is another way to specify an argument. If this command is
followed by one or more digits, optionally with a leading minus
sign, those digits define the argument. If the command is fol‐
lowed by digits, executing universal-argument again ends the
numeric argument, but is otherwise ignored. As a special case,
if this command is immediately followed by a character that is
neither a digit or minus sign, the argument count for the next
command is multiplied by four. The argument count is initially
one, so executing this function the first time makes the argu‐
ment count four, a second time makes the argument count sixteen,
and so on.
Completing
complete (TAB)
Attempt to perform completion on the text before point. Bash
attempts completion treating the text as a variable (if the text
begins with $), username (if the text begins with ~), hostname
(if the text begins with @), or command (including aliases and
functions) in turn. If none of these produces a match, filename
completion is attempted.
possible-completions (M-?)
List the possible completions of the text before point.
insert-completions (M-*)
Insert all completions of the text before point that would have
been generated by possible-completions.
menu-complete
Similar to complete, but replaces the word to be completed with
a single match from the list of possible completions. Repeated
execution of menu-complete steps through the list of possible
completions, inserting each match in turn. At the end of the
list of completions, the bell is rung and the original text is
restored. An argument of n moves n positions forward in the
list of matches; a negative argument may be used to move back‐
ward through the list. This command is intended to be bound to
TAB, but is unbound by default.
delete-char-or-list
Deletes the character under the cursor if not at the beginning
or end of the line (like delete-char). If at the end of the
line, behaves identically to possible-completions. This command
is unbound by default.
complete-filename (M-/)
Attempt filename completion on the text before point.
possible-filename-completions (C-x /)
List the possible completions of the text before point, treating
it as a filename.
complete-username (M-~)
Attempt completion on the text before point, treating it as a
username.
possible-username-completions (C-x ~)
List the possible completions of the text before point, treating
it as a username.
complete-variable (M-$)
Attempt completion on the text before point, treating it as a
shell variable.
possible-variable-completions (C-x $)
List the possible completions of the text before point, treating
it as a shell variable.
complete-hostname (M-@)
Attempt completion on the text before point, treating it as a
hostname.
possible-hostname-completions (C-x @)
List the possible completions of the text before point, treating
it as a hostname.
complete-command (M-!)
Attempt completion on the text before point, treating it as a
command name. Command completion attempts to match the text
against aliases, reserved words, shell functions, shell
builtins, and finally executable filenames, in that order.
possible-command-completions (C-x !)
List the possible completions of the text before point, treating
it as a command name.
dynamic-complete-history (M-TAB)
Attempt completion on the text before point, comparing the text
against lines from the history list for possible completion
matches.
complete-into-braces (M-{)
Perform filename completion and return the list of possible com‐
pletions enclosed within braces so the list is available to the
shell (see Brace Expansion above).
Keyboard Macros
start-kbd-macro (C-x ()
Begin saving the characters typed into the current keyboard
macro.
end-kbd-macro (C-x ))
Stop saving the characters typed into the current keyboard macro
and store the definition.
call-last-kbd-macro (C-x e)
Re-execute the last keyboard macro defined, by making the char‐
acters in the macro appear as if typed at the keyboard.
Miscellaneous
re-read-init-file (C-x C-r)
Read in the contents of the inputrc file, and incorporate any
bindings or variable assignments found there.
abort (C-g)
Abort the current editing command and ring the terminal’s bell
(subject to the setting of bell-style).
do-uppercase-version (M-a, M-b, M-x, ...)
If the metafied character x is lowercase, run the command that
is bound to the corresponding uppercase character.
prefix-meta (ESC)
Metafy the next character typed. ESC f is equivalent to Meta-f.
undo (C-_, C-x C-u)
Incremental undo, separately remembered for each line.
revert-line (M-r)
Undo all changes made to this line. This is like executing the
undo command enough times to return the line to its initial
state.
tilde-expand (M-&)
Perform tilde expansion on the current word.
set-mark (C-@, M-<space>)
Set the mark to the current point. If a numeric argument is
supplied, the mark is set to that position.
exchange-point-and-mark (C-x C-x)
Swap the point with the mark. The current cursor position is
set to the saved position, and the old cursor position is saved
as the mark.
character-search (C-])
A character is read and point is moved to the next occurrence of
that character. A negative count searches for previous occur‐
rences.
character-search-backward (M-C-])
A character is read and point is moved to the previous occur‐
rence of that character. A negative count searches for subse‐
quent occurrences.
insert-comment (M-#)
The value of the readline comment-begin variable is inserted at
the beginning of the current line, and the line is accepted as
if a newline had been typed. This makes the current line a
shell comment.
glob-expand-word (C-x *)
The word before point is treated as a pattern for pathname
expansion, and the list of matching file names is inserted,
replacing the word.
glob-list-expansions (C-x g)
The list of expansions that would have been generated by
glob-expand-word is displayed, and the line is redrawn.
dump-functions
Print all of the functions and their key bindings to the read‐
line output stream. If a numeric argument is supplied, the out‐
put is formatted in such a way that it can be made part of an
inputrc file.
dump-variables
Print all of the settable readline variables and their values to
the readline output stream. If a numeric argument is supplied,
the output is formatted in such a way that it can be made part
of an inputrc file.
dump-macros
Print all of the readline key sequences bound to macros and the
strings they ouput. If a numeric argument is supplied, the out‐
put is formatted in such a way that it can be made part of an
inputrc file.
display-shell-version (C-x C-v)
Display version information about the current instance of bash.
HISTORY
When the -o history option to the set builtin is enabled, the shell
provides access to the command history, the list of commands previously
typed. The text of the last HISTSIZE commands (default 500) is saved
in a history list. The shell stores each command in the history list
prior to parameter and variable expansion (see EXPANSION above) but
after history expansion is performed, subject to the values of the
shell variables HISTIGNORE and HISTCONTROL. On startup, the history is
initialized from the file named by the variable HISTFILE (default
~/.bash_history). HISTFILE is truncated, if necessary, to contain no
more than HISTFILESIZE lines. When an interactive shell exits, the
last HISTSIZE lines are copied from the history list to HISTFILE. If
the histappend shell option is enabled (see the description of shopt
under SHELL BUILTIN COMMANDS below), the lines are appended to the his‐
tory file, otherwise the history file is overwritten. If HISTFILE is
unset, or if the history file is unwritable, the history is not saved.
After saving the history, the history file is truncated to contain no
more than HISTFILESIZE lines. If HISTFILESIZE is not set, no trunca‐
tion is performed.
The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used
to list or edit and re-execute a portion of the history list. The his
tory builtin can be used to display or modify the history list and
manipulate the history file. When using the command-line editing,
search commands are available in each editing mode that provide access
to the history list.
The shell allows control over which commands are saved on the history
list. The HISTCONTROL and HISTIGNORE variables may be set to cause the
shell to save only a subset of the commands entered. The cmdhist shell
option, if enabled, causes the shell to attempt to save each line of a
multi-line command in the same history entry, adding semicolons where
necessary to preserve syntactic correctness. The lithist shell option
causes the shell to save the command with embedded newlines instead of
semicolons. See the description of the shopt builtin below under SHELL
BUILTIN COMMANDS for information on setting and unsetting shell
options.
The shell supports a history expansion feature that is similar to the
history expansion in csh. This section describes what syntax features
are available. This feature is enabled by default for interactive
shells, and can be disabled using the +H option to the set builtin com‐
mand (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not
perform history expansion by default.
History expansions introduce words from the history list into the input
stream, making it easy to repeat commands, insert the arguments to a
previous command into the current input line, or fix errors in previous
commands quickly.
History expansion is performed immediately after a complete line is
read, before the shell breaks it into words. It takes place in two
parts. The first is to determine which line from the history list to
use during substitution. The second is to select portions of that line
for inclusion into the current one. The line selected from the history
is the event, and the portions of that line that are acted upon are
words. Various modifiers are available to manipulate the selected
words. The line is broken into words in the same fashion as when read‐
ing input, so that several metacharacter-separated words surrounded by
quotes are considered one word. History expansions are introduced by
the appearance of the history expansion character, which is ! by
default. Only backslash (\) and single quotes can quote the history
expansion character.
Several shell options settable with the shopt builtin may be used to
tailor the behavior of history expansion. If the histverify shell
option is enabled (see the description of the shopt builtin), and read
line is being used, history substitutions are not immediately passed to
the shell parser. Instead, the expanded line is reloaded into the
readline editing buffer for further modification. If readline is being
used, and the histreedit shell option is enabled, a failed history sub‐
stitution will be reloaded into the readline editing buffer for correc‐
tion. The -p option to the history builtin command may be used to see
what a history expansion will do before using it. The -s option to the
history builtin may be used to add commands to the end of the history
list without actually executing them, so that they are available for
subsequent recall.
The shell allows control of the various characters used by the history
expansion mechanism (see the description of histchars above under Shell
Variables).
Event Designators
An event designator is a reference to a command line entry in the his‐
tory list.
! Start a history substitution, except when followed by a blank,
newline, = or (.
!n Refer to command line n.
!-n Refer to the current command line minus n.
!! Refer to the previous command. This is a synonym for ‘!-1’.
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containing string. The trail‐
ing ? may be omitted if string is followed immediately by a new‐
line.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1
with string2. Equivalent to ‘‘!!:s/string1/string2/’’ (see Mod
ifiers below).
!# The entire command line typed so far.
Word Designators
Word designators are used to select desired words from the event. A :
separates the event specification from the word designator. It may be
omitted if the word designator begins with a ^, $, *, -, or %. Words
are numbered from the beginning of the line, with the first word being
denoted by 0 (zero). Words are inserted into the current line sepa‐
rated by single spaces.
0 (zero)
The zeroth word. For the shell, this is the command word.
n The nth word.
^ The first argument. That is, word 1.
$ The last argument.
% The word matched by the most recent ‘?string?’ search.
x-y A range of words; ‘-y’ abbreviates ‘0-y’.
* All of the words but the zeroth. This is a synonym for ‘1-$’.
It is not an error to use * if there is just one word in the
event; the empty string is returned in that case.
x* Abbreviates x-$.
x- Abbreviates x-$ like x*, but omits the last word.
If a word designator is supplied without an event specification, the
previous command is used as the event.
Modifiers
After the optional word designator, there may appear a sequence of one
or more of the following modifiers, each preceded by a ‘:’.
h Remove a trailing file name component, leaving only the head.
t Remove all leading file name components, leaving the tail.
r Remove a trailing suffix of the form .xxx, leaving the basename.
e Remove all but the trailing suffix.
p Print the new command but do not execute it.
q Quote the substituted words, escaping further substitutions.
x Quote the substituted words as with q, but break into words at
blanks and newlines.
s/old/new/
Substitute new for the first occurrence of old in the event
line. Any delimiter can be used in place of /. The final
delimiter is optional if it is the last character of the event
line. The delimiter may be quoted in old and new with a single
backslash. If & appears in new, it is replaced by old. A sin‐
gle backslash will quote the &. If old is null, it is set to
the last old substituted, or, if no previous history substitu‐
tions took place, the last string in a !?string[?] search.
& Repeat the previous substitution.
g Cause changes to be applied over the entire event line. This is
used in conjunction with ‘:s’ (e.g., ‘:gs/old/new/’) or ‘:&’.
If used with ‘:s’, any delimiter can be used in place of /, and
the final delimiter is optional if it is the last character of
the event line.
Unless otherwise noted, each builtin command documented in this section
as accepting options preceded by - accepts -- to signify the end of the
options.
: [arguments]
No effect; the command does nothing beyond expanding arguments
and performing any specified redirections. A zero exit code is
returned.
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command exe‐
cuted from filename. If filename does not contain a slash, file
names in PATH are used to find the directory containing file‐
name. The file searched for in PATH need not be executable.
The current directory is searched if no file is found in PATH.
If the sourcepath option to the shopt builtin command is turned
off, the PATH is not searched. If any arguments are supplied,
they become the positional parameters when filename is executed.
Otherwise the positional parameters are unchanged. The return
status is the status of the last command exited within the
script (0 if no commands are executed), and false if filename is
not found or cannot be read.
alias [-p] [name[=value] ...]
Alias with no arguments or with the -p option prints the list of
aliases in the form alias name=value on standard output. When
arguments are supplied, an alias is defined for each name whose
value is given. A trailing space in value causes the next word
to be checked for alias substitution when the alias is expanded.
For each name in the argument list for which no value is sup‐
plied, the name and value of the alias is printed. Alias
returns true unless a name is given for which no alias has been
defined.
bg [jobspec]
Resume the suspended job jobspec in the background, as if it had
been started with &. If jobspec is not present, the shell’s
notion of the current job is used. bg jobspec returns 0 unless
run when job control is disabled or, when run with job control
enabled, if jobspec was not found or started without job con‐
trol.
bind [-m keydirectorie] [-lpsvPSV]
bind [-m keydirectorie] [-q function] [-u function] [-r keyseq]
bind [-m keydirectorie] -f filename
bind [-m keydirectorie] keyseq:function-name
Display current readline key and function bindings, or bind a
key sequence to a readline function or macro. The binding syn‐
tax accepted is identical to that of .inputrc, but each binding
must be passed as a separate argument; e.g., ’"\C-x\C-r":
re-read-init-file’. Options, if supplied, have the following
meanings:
-m keydirectorie
Use keydirectorie as the keydir to be affected by the
subsequent bindings. Acceptable keydirectorie names are
emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
vi-command, and vi-insert. vi is equivalent to vi-com‐
mand; emacs is equivalent to emacs-standard.
-l List the names of all readline functions.
-p Display readline function names and bindings in such a
way that they can be re-read.
-P List current readline function names and bindings.
-v Display readline variable names and values in such a way
that they can be re-read.
-V List current readline variable names and values.
-s Display readline key sequences bound to macros and the
strings they output in such a way that they can be re-
read.
-S Display readline key sequences bound to macros and the
strings they output.
-f filename
Read key bindings from filename.
-q function
Query about which keys invoke the named function.
-u function
Unbind all keys bound to the named function.
-r keyseq
Remove any current binding for keyseq.
The return value is 0 unless an unrecognized option is given or
an error occurred.
break [n]
Exit from within a for, while, until, or select loop. If n is
specified, break n levels. n must be ≥ 1. If n is greater than
the number of enclosing loops, all enclosing loops are exited.
The return value is 0 unless the shell is not executing a loop
when break is executed.
builtin shell-builtin [arguments]
Execute the specified shell builtin, passing it arguments, and
return its exit status. This is useful when defining a function
whose name is the same as a shell builtin, retaining the func‐
tionality of the builtin within the function. The cd builtin is
commonly redefined this way. The return status is false if
shell-builtin is not a shell builtin command.
cd [-LP] [dir]
Change the current directory to dir. The variable HOME is the
default dir. The variable CDPATH defines the search path for
the directory containing dir. Alternative directory names in
CDPATH are separated by a colon (:). A null directory name in
CDPATH is the same as the current directory, i.e., ‘‘.’’. If
dir begins with a slash (/), then CDPATH is not used. The -P
option says to use the physical directory structure instead of
following symbolic links (see also the -P option to the set
builtin command); the -L option forces symbolic links to be fol‐
lowed. An argument of - is equivalent to $OLDPWD. The return
value is true if the directory was successfully changed; false
otherwise.
command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function
lookup. Only builtin commands or commands found in the PATH are
executed. If the -p option is given, the search for command is
performed using a default value for PATH that is guaranteed to
find all of the standard utilities. If either the -V or -v
option is supplied, a description of command is printed. The -v
option causes a single word indicating the command or file name
used to invoke command to be displayed; the -V option produces a
more verbose description. If the -V or -v option is supplied,
the exit status is 0 if command was found, and 1 if not. If
neither option is supplied and an error occurred or command can‐
not be found, the exit status is 127. Otherwise, the exit sta‐
tus of the command builtin is the exit status of command.
continue [n]
Resume the next iteration of the enclosing for, while, until, or
select loop. If n is specified, resume at the nth enclosing
loop. n must be ≥ 1. If n is greater than the number of
enclosing loops, the last enclosing loop (the ‘‘top-level’’
loop) is resumed. The return value is 0 unless the shell is not
executing a loop when continue is executed.
declare [-afFirx] [-p] [name[=value]]
typeset [-afFirx] [-p] [name[=value]]
Declare variables and/or give them attributes. If no names are
given then display the values of variables. The -p option will
display the attributes and values of each name. When -p is
used, additional options are ignored. The -F option inhibits
the display of function definitions; only the function name and
attributes are printed. The -F option implies -f. The follow‐
ing options can be used to restrict output to variables with the
specified attribute or to give variables attributes:
-a Each name is an array variable (see Arrays above).
-f Use function names only.
-i The variable is treated as an integer; arithmetic evalua‐
tion (see ARITHMETIC EVALUATION ) is performed when the
variable is assigned a value.
-r Make names readonly. These names cannot then be assigned
values by subsequent assignment statements or unset.
-x Mark names for export to subsequent commands via the
environment.
Using ‘+’ instead of ‘-’ turns off the attribute instead, with
the exception that +a may not be used to destroy an array vari‐
able. When used in a function, makes each name local, as with
the local command. The return value is 0 unless an invalid
option is encountered, an attempt is made to define a function
using "-f foo=bar", an attempt is made to assign a value to a
readonly variable, an attempt is made to assign a value to an
array variable without using the compound assignment syntax (see
Arrays above), one of the names is not a valid shell variable
name, an attempt is made to turn off readonly status for a read‐
only variable, an attempt is made to turn off array status for
an array variable, or an attempt is made to display a non-exis‐
tent function with -f.
directories [-clpv] [+n] [-n]
Without options, displays the list of currently remembered
directories. The default display is on a single line with
directory names separated by spaces. Directories are added to
the list with the pushd command; the popd command removes
entries from the list.
+n Displays the nth entry counting from the left of the list
shown by directories when invoked without options, start‐
ing with zero.
-n Displays the nth entry counting from the right of the
list shown by directories when invoked without options,
starting with zero.
-c Clears the directory stack by deleting all of the
entries.
-l Produces a longer listing; the default listing format
uses a tilde to denote the home directory.
-p Print the directory stack with one entry per line.
-v Print the directory stack with one entry per line, pre‐
fixing each entry with its index in the stack.
The return value is 0 unless an invalid option is supplied or n
indexes beyond the end of the directory stack.
disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of
active jobs. If the -h option is given, each jobspec is not
removed from the table, but is marked so that SIGHUP is not sent
to the job if the shell receives a SIGHUP. If no jobspec is
present, and neither the -a nor the -r option is supplied, the
current job is used. If no jobspec is supplied, the -a option
means to remove or mark all jobs; the -r option without a job‐
spec argument restricts operation to running jobs. The return
value is 0 unless a jobspec does not specify a valid job.
echo [-neE] [arg ...]
Output the args, separated by spaces, followed by a newline.
The return status is always 0. If -n is specified, the trailing
newline is suppressed. If the -e option is given, interpreta‐
tion of the following backslash-escaped characters is enabled.
The -E option disables the interpretation of these escape char‐
acters, even on systems where they are interpreted by default.
echo does not interpret -- to mean the end of options. echo
interprets the following escape sequences:
\a alert (bell)
\b backspace
\c suppress trailing newline
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\nnn the character whose ASCII code is the octal value nnn
(one to three digits)
\xnnn the character whose ASCII code is the hexadecimal value
nnn (one to three digits)
enable [-adnps] [-f filename] [name ...]
Enable and disable builtin shell commands. Disabling a builtin
allows a disk command which has the same name as a shell builtin
to be executed with specifying a full pathname, even though the
shell normally searches for builtins before disk commands. If
-n is used, each name is disabled; otherwise, names are enabled.
For example, to use the test binary found via the PATH instead
of the shell builtin version, run enable -n test. The -f option
means to load the new builtin command name from shared object
filename, on systems that support dynamic loading. The -d
option will delete a builtin previously loaded with -f. If no
name arguments are given, or if the -p option is supplied, a
list of shell builtins is printed. With no other option argu‐
ments, the list consists of all enabled shell builtins. If -n
is supplied, only disabled builtins are printed. If -a is sup‐
plied, the list printed includes all builtins, with an indica‐
tion of whether or not each is enabled. If -s is supplied, the
output is restricted to the POSIX special builtins. The return
value is 0 unless a name is not a shell builtin or there is a
problem loading a new builtin from a shared object.
eval [arg ...]
The args are read and concatenated together into a single com‐
mand. This command is then read and executed by the shell, and
its exit status is returned as the value of eval. If there are
no args, or only null arguments, eval returns 0.
exec [-cl] [-a name] [command [arguments]]
If command is specified, it replaces the shell. No new process
is created. The arguments become the arguments to command. If
the -l option is supplied, the shell places a dash in the zeroth
arg passed to command. This is what login(1) does. The -c
option causes command to be executed with an empty environment.
If -a is supplied, the shell passes name as the zeroth argument
to the executed command. If command cannot be executed for some
reason, a non-interactive shell exits, unless the shell option
execfail is enabled, in which case it returns failure. An
interactive shell returns failure if the file cannot be exe‐
cuted. If command is not specified, any redirections take
effect in the current shell, and the return status is 0. If
there is a redirection error, the return status is 1.
exit [n]
Cause the shell to exit with a status of n. If n is omitted,
the exit status is that of the last command executed. A trap on
EXIT is executed before the shell terminates.
export [-fn] [name[=word]] ...
export -p
The supplied names are marked for automatic export to the envi‐
ronment of subsequently executed commands. If the -f option is
given, the names refer to functions. If no names are given, or
if the -p option is supplied, a list of all names that are
exported in this shell is printed. The -n option causes the
export property to be removed from the named variables. export
returns an exit status of 0 unless an invalid option is encoun‐
tered, one of the names is not a valid shell variable name, or
-f is supplied with a name that is not a function.
fc [-e ename] [-nlr] [first] [last]
fc -s [pat=rep] [cmd]
Fix Command. In the first form, a range of commands from first
to last is selected from the history list. First and last may
be specified as a string (to locate the last command beginning
with that string) or as a number (an index into the history
list, where a negative number is used as an offset from the cur‐
rent command number). If last is not specified it is set to the
current command for listing (so that fc -l -10 prints the last
10 commands) and to first otherwise. If first is not specified
it is set to the previous command for editing and -16 for list‐
ing.
The -n option suppresses the command numbers when listing. The
-r option reverses the order of the commands. If the -l option
is given, the commands are listed on standard output. Other‐
wise, the editor given by ename is invoked on a file containing
those commands. If ename is not given, the value of the FCEDIT
variable is used, and the value of EDITOR if FCEDIT is not set.
If neither variable is set, vi is used. When editing is com‐
plete, the edited commands are echoed and executed.
In the second form, command is re-executed after each instance
of pat is replaced by rep. A useful alias to use with this is
‘‘r=fc -s’’, so that typing ‘‘r cc’’ runs the last command
beginning with ‘‘cc’’ and typing ‘‘r’’ re-executes the last com‐
mand.
If the first form is used, the return value is 0 unless an
invalid option is encountered or first or last specify history
lines out of range. If the -e option is supplied, the return
value is the value of the last command executed or failure if an
error occurs with the temporary file of commands. If the second
form is used, the return status is that of the command re-exe‐
cuted, unless cmd does not specify a valid history line, in
which case fc returns failure.
fg [jobspec]
Resume jobspec in the foreground, and make it the current job.
If jobspec is not present, the shell’s notion of the current job
is used. The return value is that of the command placed into
the foreground, or failure if run when job control is disabled
or, when run with job control enabled, if jobspec does not spec‐
ify a valid job or jobspec specifies a job that was started
without job control.
getopts optstring name [args]
getopts is used by shell procedures to parse positional parame‐
ters. optstring contains the option letters to be recognized;
if a letter is followed by a colon, the option is expected to
have an argument, which should be separated from it by white
space. Each time it is invoked, getopts places the next option
in the shell variable name, initializing name if it does not
exist, and the index of the next argument to be processed into
the variable OPTIND. OPTIND is initialized to 1 each time the
shell or a shell script is invoked. When an option requires an
argument, getopts places that argument into the variable OPTARG.
The shell does not reset OPTIND automatically; it must be manu‐
ally reset between multiple calls to getopts within the same
shell invocation if a new set of parameters is to be used.
When the end of options is encountered, getopts exits with a
return value greater than zero. OPTIND is set to the index of
the first non-option argument, and name is set to ?.
getopts normally parses the positional parameters, but if more
arguments are given in args, getopts parses those instead.
getopts can report errors in two ways. If the first character
of optstring is a colon, silent error reporting is used. In
normal operation diagnostic messages are printed when invalid
options or missing option arguments are encountered. If the
variable OPTERR is set to 0, no error messages will be dis‐
played, even if the first character of optstring is not a colon.
If an invalid option is seen, getopts places ? into name and, if
not silent, prints an error message and unsets OPTARG. If
getopts is silent, the option character found is placed in
OPTARG and no diagnostic message is printed.
If a required argument is not found, and getopts is not silent,
a question mark (?) is placed in name, OPTARG is unset, and a
diagnostic message is printed. If getopts is silent, then a
colon (:) is placed in name and OPTARG is set to the option
character found.
getopts returns true if an option, specified or unspecified, is
found. It returns false if the end of options is encountered or
an error occurs.
hash [-r] [-p filename] [name]
For each name, the full file name of the command is determined
by searching the directories in $PATH and remembered. If the -p
option is supplied, no path search is performed, and filename is
used as the full file name of the command. The -r option causes
the shell to forget all remembered locations. If no arguments
are given, information about remembered commands is printed.
The return status is true unless a name is not found or an
invalid option is supplied.
help [pattern]
Display helpful information about builtin commands. If pattern
is specified, help gives detailed help on all commands matching
pattern; otherwise help for all the builtins and shell control
structures is printed. The return status is 0 unless no command
matches pattern.
history [-c] [n]
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]
With no options, display the command history list with line num‐
bers. Lines listed with a * have been modified. An argument of
n lists only the last n lines. If filename is supplied, it is
used as the name of the history file; if not, the value of HIST
FILE is used. Options, if supplied, have the following mean‐
ings:
-a Append the ‘‘new’’ history lines (history lines entered
since the beginning of the current bash session) to the
history file.
-n Read the history lines not already read from the history
file into the current history list. These are lines
appended to the history file since the beginning of the
current bash session.
-r Read the contents of the history file and use them as the
current history.
-w Write the current history to the history file, overwrit‐
ing the history file’s contents.
-c Clear the history list by deleting all the entries.
-p Perform history substitution on the following args and
display the result on the standard output. Does not
store the results in the history list. Each arg must be
quoted to disable normal history expansion.
-s Store the args in the history list as a single entry.
The last command in the history list is removed before
the args are added.
The return value is 0 unless an invalid option is encountered or
an error occurs while reading or writing the history file.
jobs [-lnprs] [ jobspec ... ]
jobs -x command [ args ... ]
The first form lists the active jobs. The options have the fol‐
lowing meanings:
-l List process IDs in addition to the normal information.
-p List only the process ID of the job’s process group
leader.
-n Display information only about jobs that have changed
status since the user was last notified of their status.
-r Restrict output to running jobs.
-s Restrict output to stopped jobs.
If jobspec is given, output is restricted to information about
that job. The return status is 0 unless an invalid option is
encountered or an invalid jobspec is supplied.
If the -x option is supplied, jobs replaces any jobspec found in
command or args with the corresponding process group ID, and
executes command passing it args, returning its exit status.
kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
kill -l [sigspec | exit_status]
Send the signal named by sigspec or signum to the processes
named by pid or jobspec. sigspec is either a signal name such
as SIGKILL or a signal number; signum is a signal number. If
sigspec is a signal name, the name may be given with or without
the SIG prefix. If sigspec is not present, then SIGTERM is
assumed. An argument of -l lists the signal names. If any
arguments are supplied when -l is given, the names of the
signals corresponding to the arguments are listed, and the
return status is 0. The exit_status argument to -l is a number
specifying either a signal number or the exit status of a pro‐
cess terminated by a signal. kill returns true if at least one
signal was successfully sent, or false if an error occurs or an
invalid option is encountered.
let arg [arg ...]
Each arg is an arithmetic expression to be evaluated (see ARITH
METIC EVALUATION). If the last arg evaluates to 0, let returns
1; 0 is returned otherwise.
local [name[=value] ...]
For each argument, a local variable named name is created, and
assigned value. When local is used within a function, it causes
the variable name to have a visible scope restricted to that
function and its children. With no operands, local writes a
list of local variables to the standard output. It is an error
to use local when not within a function. The return status is 0
unless local is used outside a function, or an invalid name is
supplied.
logout Exit a login shell.
popd [-n] [+n] [-n]
Removes entries from the directory stack. With no arguments,
removes the top directory from the stack, and performs a cd to
the new top directory. Arguments, if supplied, have the follow‐
ing meanings:
+n Removes the nth entry counting from the left of the list
shown by directories, starting with zero. For example:
‘‘popd +0’’ removes the first directory, ‘‘popd +1’’ the
second.
-n Removes the nth entry counting from the right of the list
shown by directories, starting with zero. For example:
‘‘popd -0’’ removes the last directory, ‘‘popd -1’’ the
next to last.
-n Suppresses the normal change of directory when removing
directories from the stack, so that only the stack is
manipulated.
If the popd command is successful, a directories is performed as
well, and the return status is 0. popd returns false if an
invalid option is encountered, the directory stack is empty, a
non-existent directory stack entry is specified, or the direc‐
tory change fails.
printf format [arguments]
Write the formatted arguments to the standard output under the
control of the format. The format is a character string which
contains three types of objects: plain characters, which are
simply copied to standard output, character escape sequences,
which are converted and copied to the standard output, and for‐
mat specifications, each of which causes printing of the next
successive argument. In addition to the standard printf(1) for‐
mats, %b causes printf to expand backslash escape sequences in
the corresponding argument, and %q causes printf to output the
corresponding argument in a format that can be reused as shell
input.
The format is reused as necessary to consume all of the argu‐
ments. If the format requires more arguments than are supplied,
the extra format specifications behave as if a zero value or
null string, as appropriate, had been supplied.
pushd [-n] [dir]
pushd [-n] [+n] [-n]
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory. With no arguments, exchanges the top two directories
and returns 0, unless the directory stack is empty. Arguments,
if supplied, have the following meanings:
+n Rotates the stack so that the nth directory (counting
from the left of the list shown by directories, starting
with zero) is at the top.
-n Rotates the stack so that the nth directory (counting
from the right of the list shown by directories, starting
with zero) is at the top.
-n Suppresses the normal change of directory when adding
directories to the stack, so that only the stack is
manipulated.
dir Adds dir to the directory stack at the top, making it the
new current working directory.
If the pushd command is successful, a directories is performed
as well. If the first form is used, pushd returns 0 unless the
cd to dir fails. With the second form, pushd returns 0 unless
the directory stack is empty, a non-existent directory stack
element is specified, or the directory change to the specified
new current directory fails.
pwd [-LP]
Print the absolute file name of the current working directory.
The file name printed contains no symbolic links if the -P
option is supplied or the -o physical option to the set builtin
command is enabled. If the -L option is used, symbolic links
are followed. The return status is 0 unless an error occurs
while reading the name of the current directory or an invalid
option is supplied.
read [-er] [-a aname] [-p prompt] [name ...]
One line is read from the standard input, and the first word is
assigned to the first name, the second word to the second name,
and so on, with leftover words and their intervening separators
assigned to the last name. If there are fewer words read from
the standard input than names, the remaining names are assigned
empty values. The characters in IFS are used to split the line
into words. The backslash character (\) may be used to remove
any special meaning for the next character read and for line
continuation. Options, if supplied, have the following mean‐
ings:
-r Backslash does not act as an escape character. The back‐
slash is considered to be part of the line. In particu‐
lar, a backslash-newline pair may not be used as a line
continuation.
-p Display prompt, without a trailing newline, before
attempting to read any input. The prompt is displayed
only if input is coming from a terminal.
-a The words are assigned to sequential indices of the array
variable aname, starting at 0. aname is unset before any
new values are assigned. Other name arguments are
ignored.
-e If the standard input is coming from a terminal, readline
(see READLINE above) is used to obtain the line.
If no names are supplied, the line read is assigned to the vari‐
able REPLY. The return code is zero, unless end-of-file is
encountered.
readonly [-apf] [name ...]
The given names are marked readonly; the values of these names
may not be changed by subsequent assignment. If the -f option
is supplied, the functions corresponding to the names are so
marked. The -a option restricts the variables to arrays. If no
name arguments are given, or if the -p option is supplied, a
list of all readonly names is printed. The -p option causes
output to be displayed in a format thatmay be reused as input.
The return status is 0 unless an invalid option is encountered,
one of the names is not a valid shell variable name, or -f is
supplied with a name that is not a function.
return [n]
Causes a function to exit with the return value specified by n.
If n is omitted, the return status is that of the last command
executed in the function body. If used outside a function, but
during execution of a script by the . (source) command, it
causes the shell to stop executing that script and return either
n or the exit status of the last command executed within the
script as the exit status of the script. If used outside a
function and not during execution of a script by ., the return
status is false.
set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Without options, the name and value of each shell variable are
displayed in a format that can be reused as input. The output
is sorted according to the current locale. When options are
specified, they set or unset shell attributes. Any arguments
remaining after the options are processed are treated as values
for the positional parameters and are assigned, in order, to $1,
$2, ... $n. Options, if specified, have the following mean‐
ings:
-a Automatically mark variables which are modified or cre‐
ated for export to the environment of subsequent com‐
mands.
-b Report the status of terminated background jobs immedi‐
ately, rather than before the next primary prompt. This
is effective only when job control is enabled.
-e Exit immediately if a simple command (see SHELL GRAMMAR
above) exits with a non-zero status. The shell does not
exit if the command that fails is part of an until or
while loop, part of an if statement, part of a && or
list, or if the command’s return value is being inverted
via !.
-f Disable pathname expansion.
-h Remember the location of commands as they are looked up
for execution. This is enabled by default.
-k All arguments in the form of assignment statements are
placed in the environment for a command, not just those
that precede the command name.
-m Monitor mode. Job control is enabled. This option is
on by default for interactive shells on systems that
support it (see JOB CONTROL above). Background pro‐
cesses run in a separate process group and a line con‐
taining their exit status is printed upon their comple‐
tion.
-n Read commands but do not execute them. This may be used
to check a shell script for syntax errors. This is
ignored by interactive shells.
-o option-name
The option-name can be one of the following:
allexport
Same as -a.
braceexpand
Same as -B.
emacs Use an emacs-style command line editing inter‐
face. This is enabled by default when the shell
is interactive, unless the shell is started with
the --noediting option.
errexit Same as -e.
hashall Same as -h.
histexpand
Same as -H.
history Enable command history, as described above under
HISTORY. This option is on by default in inter‐
active shells.
ignoreeof
The effect is as if the shell command
IGNOREEOF=10 had been executed (see Shell Vari
ables above).
keyword Same as -k.
monitor Same as -m.
noclobber
Same as -C.
noexec Same as -n.
noglob Same as -f.
notify Same as -b.
nounset Same as -u.
onecmd Same as -t.
physical
Same as -P.
posix Change the behavior of bash where the default
operation differs from the POSIX 1003.2 standard
to match the standard.
privileged
Same as -p.
verbose Same as -v.
vi Use a vi-style command line editing interface.
xtrace Same as -x.
If -o is supplied with no option-name, the values of the
current options are printed. If +o is supplied with no
option-name, a series of set commands to recreate the
current option settings is displayed on the standard
output.
-p Turn on privileged mode. In this mode, the $ENV and
$BASH_ENV files are not processed, shell functions are
not inherited from the environment, and the SHELLOPTS
variable, if it appears in the environment, is ignored.
If the shell is started with the effective user (group)
id not equal to the real user (group) id, and the -p
option is not supplied, these actions are taken and the
effective user id is set to the real user id. If the -p
option is supplied at startup, the effective user id is
not reset. Turning this option off causes the effective
user and group ids to be set to the real user and group
ids.
-t Exit after reading and executing one command.
-u Treat unset variables as an error when performing param‐
eter expansion. If expansion is attempted on an unset
variable, the shell prints an error message, and, if not
interactive, exits with a non-zero status.
-v Print shell input lines as they are read.
-x After expanding each simple command, display the
expanded value of PS4, followed by the command and its
expanded arguments.
-B The shell performs brace expansion (see Brace Expansion
above). This is on by default.
-C If set, bash does not overwrite an existing file with
the >, >&, and <> redirection operators. This may be
overridden when creating output files by using the redi‐
rection operator >| instead of >.
-H Enable ! style history substitution. This option is on
by default when the shell is interactive.
-P If set, the shell does not follow symbolic links when
executing commands such as cd that change the current
working directory. It uses the physical directory
structure instead. By default, bash follows the logical
chain of directories when performing commands which
change the current directory.
-- If no arguments follow this option, then the positional
parameters are unset. Otherwise, the positional parame‐
ters are set to the args, even if some of them begin
with a -.
- Signal the end of options, cause all remaining args to
be assigned to the positional parameters. The -x and -v
options are turned off. If there are no args, the posi‐
tional parameters remain unchanged.
The options are off by default unless otherwise noted. Using +
rather than - causes these options to be turned off. The
options can also be specified as arguments to an invocation of
the shell. The current set of options may be found in $-. The
return status is always true unless an invalid option is encoun‐
tered.
shift [n]
The positional parameters from n+1 ... are renamed to $1 ....
Parameters represented by the numbers $# down to $#-n+1 are
unset. n must be a non-negative number less than or equal to
$#. If n is 0, no parameters are changed. If n is not given,
it is assumed to be 1. If n is greater than $#, the positional
parameters are not changed. The return status is greater than
zero if n is greater than $# or less than zero; otherwise 0.
shopt [-pqsu] [-o] [optname ...]
Toggle the values of variables controlling optional shell behav‐
ior. With no options, or with the -p option, a list of all set‐
table options is displayed, with an indication of whether or not
each is set. The -p option causes output to be displayed in a
form that may be reused as input. Other options have the fol‐
lowing meanings:
-s Enable (set) each optname.
-u Disable (unset) each optname.
-q Suppresses normal output (quiet mode); the return status
indicates whether the optname is set or unset. If multi‐
ple optname arguments are given with -q, the return sta‐
tus is zero if all optnames are enabled; non-zero other‐
wise.
-o Restricts the values of optname to be those defined for
the -o option to the set builtin.
If either -s or -u is used with no optname arguments, the dis‐
play is limited to those options which are set or unset, respec‐
tively. Unless otherwise noted, the shopt options are disabled
(unset) by default.
The return status when listing options is zero if all optnames
are enabled, non-zero otherwise. When setting or unsetting
options, the return status is zero unless an optname is not a
valid shell option.
The list of shopt options is:
cdable_vars
If set, an argument to the cd builtin command that is
not a directory is assumed to be the name of a variable
whose value is the directory to change to.
cdspell If set, minor errors in the spelling of a directory com‐
ponent in a cd command will be corrected. The errors
checked for are transposed characters, a missing charac‐
ter, and one character too many. If a correction is
found, the corrected file name is printed, and the com‐
mand proceeds. This option is only used by interactive
shells.
checkhash
If set, bash checks that a command found in the hash ta‐
ble exists before trying to execute it. If a hashed
command no longer exists, a normal path search is
performed.
checkwinsize
If set, bash checks the window size after each command
and, if necessary, updates the values of LINES and
COLUMNS.
cmdhist If set, bash attempts to save all lines of a multiple-
line command in the same history entry. This allows
easy re-editing of multi-line commands.
dotglob If set, bash includes filenames beginning with a ‘.’ in
the results of pathname expansion.
execfail
If set, a non-interactive shell will not exit if it can‐
not execute the file specified as an argument to the
exec builtin command. An interactive shell does not
exit if exec fails.
expand_aliases
If set, aliases are expanded as described above under
ALIASES. This option is enabled by default for interac‐
tive shells.
extglob If set, the extended pattern matching features described
above under Pathname Expansion are enabled.
histappend
If set, the history list is appended to the file named
by the value of the HISTFILE variable when the shell
exits, rather than overwriting the file.
histreedit
If set, and readline is being used, a user is given the
opportunity to re-edit a failed history substitution.
histverify
If set, and readline is being used, the results of his‐
tory substitution are not immediately passed to the
shell parser. Instead, the resulting line is loaded
into the readline editing buffer, allowing further modi‐
fication.
hostcomplete
If set, and readline is being used, bash will attempt to
perform hostname completion when a word containing a @
is being completed (see Completing under READLINE
above). This is enabled by default.
huponexit
If set, bash will send SIGHUP to all jobs when an inter‐
active login shell exits.
interactive_comments
If set, allow a word beginning with # to cause that word
and all remaining characters on that line to be ignored
in an interactive shell (see COMMENTS above). This
option is enabled by default.
lithist If set, and the cmdhist option is enabled, multi-line
commands are saved to the history with embedded newlines
rather than using semicolon separators where possible.
mailwarn
If set, and a file that bash is checking for mail has
been accessed since the last time it was checked, the
message ‘‘The mail in mailfile has been read’’ is dis‐
played.
nocaseglob
If set, bash matches filenames in a case-insensitive
fashion when performing pathname expansion (see Pathname
Expansion above).
nullglob
If set, bash allows patterns which match no files (see
Pathname Expansion above) to expand to a null string,
rather than themselves.
promptvars
If set, prompt strings undergo variable and parameter
expansion after being expanded as described in PROMPTING
above. This option is enabled by default.
restricted_shell
The shell sets this option if it is started in
restricted mode (see RESTRICTED SHELL below). The value
may not be changed. This is not reset when the startup
files are executed, allowing the startup files to dis‐
cover whether or not a shell is restricted.
shift_verbose
If set, the shift builtin prints an error message when
the shift count exceeds the number of positional parame‐
ters.
sourcepath
If set, the source (.) builtin uses the value of PATH to
find the directory containing the file supplied as an
argument. This option is enabled by default.
suspend [-f]
Suspend the execution of this shell until it receives a SIGCONT
signal. The -f option says not to complain if this is a login
shell; just suspend anyway. The return status is 0 unless the
shell is a login shell and -f is not supplied, or if job control
is not enabled.
test expr
[ expr ]
Return a status of 0 or 1 depending on the evaluation of the
conditional expression expr. Each operator and operand must be
a separate argument. Expressions are composed of the primaries
described above under CONDITIONAL EXPRESSIONS.
Expressions may be combined using the following operators,
listed in decreasing order of precedence.
! expr True if expr is false.
( expr )
Returns the value of expr. This may be used to override
the normal precedence of operators.
expr1 -a expr2
True if both expr1 and expr2 are true.
expr1 -o expr2
True if either expr1 or expr2 is true.
test and [ evaluate conditional expressions using a set of rules
based on the number of arguments.
0 arguments
The expression is false.
1 argument
The expression is true if and only if the argument is not
null.
2 arguments
If the first argument is !, the expression is true if and
only if the second argument is null. If the first
argument is one of the unary conditional operators listed
above under CONDITIONAL EXPRESSIONS, the expression is
true if the unary test is true. If the first argument is
not a valid unary conditional operator, the expression is
false.
3 arguments
If the second argument is one of the binary conditional
operators listed above under CONDITIONAL EXPRESSIONS, the
result of the expression is the result of the binary test
using the first and third arguments as operands. If the
first argument is !, the value is the negation of the
two-argument test using the second and third arguments.
If the first argument is exactly ( and the third argument
is exactly ), the result is the one-argument test of the
second argument. Otherwise, the expression is false.
The -a and -o operators are considered binary operators
in this case.
4 arguments
If the first argument is !, the result is the negation of
the three-argument expression composed of the remaining
arguments. Otherwise, the expression is parsed and eval‐
uated according to precedence using the rules listed
above.
5 or more arguments
The expression is parsed and evaluated according to
precedence using the rules listed above.
times Print the accumulated user and system times for the shell and
for processes run from the shell. The return status is 0.
trap [-lp] [arg] [sigspec ...]
The command arg is to be read and executed when the shell
receives signal(s) sigspec. If arg is absent or -, all speci‐
fied signals are reset to their original values (the values they
had upon entrance to the shell). If arg is the null string the
signal specified by each sigspec is ignored by the shell and by
the commands it invokes. If arg is -p then the trap commands
associated with each sigspec are displayed. If no arguments are
supplied or if only -p is given, trap prints the list of com‐
mands associated with each signal number. Each sigspec is
either a signal name defined in <signal.h>, or a signal number.
If a sigspec is EXIT (0) the command arg is executed on exit
from the shell. If a sigspec is DEBUG, the command arg is exe‐
cuted after every simple command (see SHELL GRAMMAR above). The
-l option causes the shell to print a list of signal names and
their corresponding numbers. Signals ignored upon entry to the
shell cannot be trapped or reset. Trapped signals are reset to
their original values in a child process when it is created.
The return status is false if any sigspec is invalid; otherwise
trap returns true.
type [-atp] name [name ...]
With no options, indicate how each name would be interpreted if
used as a command name. If the -t option is used, type prints a
string which is one of alias, keyword, function, builtin, or
file if name is an alias, shell reserved word, function,
builtin, or disk file, respectively. If the name is not found,
then nothing is printed, and an exit status of false is
returned. If the -p option is used, type either returns the
name of the disk file that would be executed if name were speci‐
fied as a command name, or nothing if type -t name would not
return file. If a command is hashed, -p prints the hashed
value, not necessarily the file that appears first in PATH. If
the -a option is used, type prints all of the places that con‐
tain an executable named name. This includes aliases and func‐
tions, if and only if the -p option is not also used. The table
of hashed commands is not consulted when using -a. type returns
true if any of the arguments are found, false if none are found.
ulimit [-SHacdflmnpstuv [limit]]
Provides control over the resources available to the shell and
to processes started by it, on systems that allow such control.
The value of limit can be a number in the unit specified for the
resource, or the value unlimited. The -H and -S options specify
that the hard or soft limit is set for the given resource. A
hard limit cannot be increased once it is set; a soft limit may
be increased up to the value of the hard limit. If neither -H
nor -S is specified, both the soft and hard limits are set. If
limit is omitted, the current value of the soft limit of the
resource is printed, unless the -H option is given. When more
than one resource is specified, the limit name and unit are
printed before the value. Other options are interpreted as fol‐
lows:
-a All current limits are reported
-c The maximum size of core files created
-d The maximum size of a process’s data segment
-f The maximum size of files created by the shell
-l The maximum size that may be locked into memory
-m The maximum resident set size
-n The maximum number of open file descriptors (most systems
do not allow this value to be set)
-p The pipe size in 512-byte blocks (this may not be set)
-s The maximum stack size
-t The maximum amount of cpu time in seconds
-u The maximum number of processes available to a single
user
-v The maximum amount of virtual memory available to the
shell
If limit is given, it is the new value of the specified resource
(the -a option is display only). If no option is given, then -f
is assumed. Values are in 1024-byte increments, except for -t,
which is in seconds, -p, which is in units of 512-byte blocks,
and -n and -u, which are unscaled values. The return status is
0 unless an invalid option is encountered, a non-numeric argu‐
ment other than unlimited is supplied as limit, or an error
occurs while setting a new limit.
umask [-p] [-S] [mode]
The user file-creation mask is set to mode. If mode begins with
a digit, it is interpreted as an octal number; otherwise it is
interpreted as a symbolic mode mask similar to that accepted by
chmod(1). If mode is omitted, or if the -S option is supplied,
the current value of the mask is printed. The -S option causes
the mask to be printed in symbolic form; the default output is
an octal number. If the -p option is supplied, and mode is
omitted, the output is in a form that may be reused as input.
The return status is 0 if the mode was successfully changed or
if no mode argument was supplied, and false otherwise.
unalias [-a] [name ...]
Remove names from the list of defined aliases. If -a is sup‐
plied, all alias definitions are removed. The return value is
true unless a supplied name is not a defined alias.
unset [-fv] [name ...]
For each name, remove the corresponding variable or function.
If no options are supplied, or the -v option is given, each name
refers to a shell variable. Read-only variables may not be
unset. If -f is specifed, each name refers to a shell function,
and the function definition is removed. Each unset variable or
function is removed from the environment passed to subsequent
commands. If any of RANDOM, SECONDS, LINENO, HISTCMD, or
DIRSTACK are unset, they lose their special properties, even if
they are subsequently reset. The exit status is true unless a
name does not exist or is readonly.
wait [n]
Wait for the specified process and return its termination sta‐
tus. n may be a process ID or a job specification; if a job
spec is given, all processes in that job’s pipeline are waited
for. If n is not given, all currently active child processes
are waited for, and the return status is zero. If n specifies a
non-existent process or job, the return status is 127. Other‐
wise, the return status is the exit status of the last process
or job waited for.
If bash is started with the name rbash, or the -r option is supplied at
invocation, the shell becomes restricted. A restricted shell is used
to set up an environment more controlled than the standard shell. It
behaves identically to bash with the exception that the following are
disallowed or not performed:
· changing directories with cd
· setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV
· specifying command names containing /
· specifying a file name containing a / as an argument to the .
builtin command
· importing function definitions from the shell environment at
startup
· parsing the value of SHELLOPTS from the shell environment at
startup
· redirecting output using the >, >|, <>, >&, &>, and >> redirec‐
tion operators
· using the exec builtin command to replace the shell with another
command
· adding or deleting builtin commands with the -f and -d options
to the enable builtin command
· specifying the -p option to the command builtin command
· turning off restricted mode with set +r or set +o restricted.
These restrictions are enforced after any startup files are read.
When a command that is found to be a shell script is executed (see COM
MAND EXECUTION above), rbash turns off any restrictions in the shell
spawned to execute the script.
Bash Features, Brian Fox and Chet Ramey
The Gnu Readline Library, Brian Fox and Chet Ramey
The Gnu History Library, Brian Fox and Chet Ramey
Portable Operating System Interface (POSIX) Part 2: Shell and Utili‐
ties, IEEE
sh(1), ksh(1), csh(1)
emacs(1), vi(1)
readline(3)
FILES
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for login shells
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login
shell exits
~/.inputrc
Individual readline initialization file
AUTHORS
Brian Fox, Free Software Foundation
bfox@gnu.ai.MIT.Edu
Chet Ramey, Case Western Reserve University
chet@ins.CWRU.Edu
If you find a bug in bash, you should report it. But first, you should
make sure that it really is a bug, and that it appears in the latest
version of bash that you have.
Once you have determined that a bug actually exists, use the bashbug
command to submit a bug report. If you have a fix, you are encouraged
to mail that as well! Suggestions and ‘philosophical’ bug reports may
be mailed to bug-bash@gnu.org or posted to the Usenet newsgroup
gnu.bash.bug.
ALL bug reports should include:
The version number of bash
The hardware and operating system
The compiler used to compile
A description of the bug behaviour
A short script or ‘recipe’ which exercises the bug
bashbug inserts the first three items automatically into the template
it provides for filing a bug report.
Comments and bug reports concerning this manual page should be directed
to chet@ins.CWRU.Edu.
BUGS
It’s too big and too slow.
There are some subtle differences between bash and traditional versions
of sh, mostly because of the POSIX specification.
Aliases are confusing in some uses.
Shell builtin commands and functions are not stoppable/restartable.
Compound commands and command sequences of the form ‘a ; b ; c’ are not
handled gracefully when process suspension is attempted. When a pro‐
cess is stopped, the shell immediately executes the next command in the
sequence. It suffices to place the sequence of commands between paren‐
theses to force it into a subshell, which may be stopped as a unit.
Commands inside of $(...) command substitution are not parsed until
substitution is attempted. This will delay error reporting until some
time after the command is entered.
Array variables may not (yet) be exported.
VERTALING
Dit is de handleiding van bash 2.03. Alles wat tussen ‘{#’..‘#}’
staat is aanvullende vertaling, en hoort niet bij de originele handlei‐
ding. Dit is anders dan de andere handleidingen omdat de tekens ‘{’ en
‘}’ intensief door bash gebruikt worden. Het string {# komt wel voor
(tabellen,???), maar niet samen met #}. Email naar <manpages-
nl@nl.linux.org>.
$Id: bash.1,v 1.1.1.1 2004/03/21 21:02:25 cor Exp $