π Hoofdstuk 10.3: Het Instellen van de Werkomgeving in Linux
ββββββββββββββββββββββββββββββββββββββββββββ
π Omgevingsvariabelen in Bash
ββββββββββββββββββββββββββββββββββββββββββββ
β Variabelen zijn hoofdlettergevoelig en bepalen gedrag van de shell.
Bekijk variabelen:
β’ printenv β Toont omgevingsvariabelen
β’ env β Alternatief voor printenv
β’ set β Toont shell- en omgevingsvariabelen
β’ echo $NAAM β Toont de waarde van een variabele
Veelgebruikte variabelen:
Naam | Beschrijving
-------------|----------------------------
HISTCONTROL | Geschiedenisbeheer
HISTSIZE | Maximaal aantal opgeslagen commandoβs
PATH | Paden naar uitvoerbare bestanden
PS1 | Primaire shell-prompt
SHELL | Locatie van shell-programma
USER | Ingelogde gebruikersnaam
Voorbeeld:
export MYVAR="Hallo Wereld"
echo $MYVAR
β Voeg toe aan `~/.bashrc` of `~/.bash_profile` om permanent te maken.
ββββββββββββββββββββββββββββββββββββββββββββ
π₯ Soorten Bash-Sessies
ββββββββββββββββββββββββββββββββββββββββββββ
β’ Login-shell β bij aanmelding op TTY/SSH
β’ Interactieve shell β via `bash`
β’ Niet-interactieve shell β bij scripts
Login-shell controleren:
echo $0
β Bevat `-bash` = login-shell
ββββββββββββββββββββββββββββββββββββββββββββ
π€ Gebruikersspecifieke Configuratiebestanden
ββββββββββββββββββββββββββββββββββββββββββββ
Bestand | Wanneer geladen?
--------------------|-------------------
~/.bash_profile | Bij login-shell
~/.bash_login | Alternatief
~/.profile | Vooral op Debian
~/.bashrc | Altijd bij subshell
β ~/.bashrc wordt vaak aangemaakt via /etc/skel/
ββββββββββββββββββββββββββββββββββββββββββββ
π Globale Instellingen voor Alle Gebruikers
ββββββββββββββββββββββββββββββββββββββββββββ
Bestand | Functie
---------------------|--------------------------------------
/etc/profile | Omgevingsinstellingen bij login
/etc/profile.d/*.sh | Scripts die automatisch worden geladen
/etc/bashrc | Voor elke shell (of /etc/bash.bashrc)
Voorbeeld: globale variabele instellen
sudo nano /etc/profile.d/welkom.sh
Voeg toe:
export WELKOMSTBERICHT="Welkom op deze server!"
Herlaad zonder uitloggen:
source /etc/profile
β Bewerk liever `/etc/profile.d/*.sh` i.p.v. direct `/etc/profile`