Bash/bash-completion: Unterschied zwischen den Versionen
K Textersetzung - „Man-Pages“ durch „Man-Page“ |
|||
(18 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 2: | Zeile 2: | ||
= Installation = | = Installation = | ||
apt install bash-completion | # '''apt install bash-completion''' | ||
= Aktivierung = | = Aktivierung = | ||
== Aktivierung | == Aktivierung für alle Benutzer == | ||
'''/etc/bash.bashrc''' | |||
if ! shopt -oq posix; then | if ! shopt -oq posix; then | ||
if [ -f /usr/share/bash-completion/bash_completion ]; then | if [ -f /usr/share/bash-completion/bash_completion ]; then | ||
Zeile 15: | Zeile 15: | ||
fi | fi | ||
== Aktivierung pro Benutzer == | |||
'''~/.bashrc''' | |||
== Aktivierung | |||
/ | |||
if ! shopt -oq posix; then | if ! shopt -oq posix; then | ||
if [ -f /usr/share/bash-completion/bash_completion ]; then | if [ -f /usr/share/bash-completion/bash_completion ]; then | ||
Zeile 33: | Zeile 25: | ||
fi | fi | ||
= | To try it without logging out and back in, run: | ||
'''$ . ~/.bashrc''' | |||
= Funktionsweise = | |||
* the . in front of /etc/bash_completion does not refer to the current directory, since it has spaces around it. | * the . in front of /etc/bash_completion does not refer to the current directory, since it has spaces around it. | ||
* It instead makes the contents of the given file be evaluated in the currently running shell, instead of being executed in a new subshell. It is standardized here. | * It instead makes the contents of the given file be evaluated in the currently running shell, instead of being executed in a new subshell. It is standardized here. | ||
Zeile 41: | Zeile 36: | ||
* This is why if you cd into a different path in a shell script, you won't be in that path when the script exits like you would be in a .BAT. | * This is why if you cd into a different path in a shell script, you won't be in that path when the script exits like you would be in a .BAT. | ||
== | == Anwendung == | ||
* Then try to use tab-completion | |||
* That dot and space at the beginning (.) is the same as using the source keyword in bash, but is more portable. | |||
* If you want it to work when su'd into the root account, do the same thing in root's home directory (typically /root). | |||
= Links = | = Links = | ||
== Dateien == | |||
== Man-Page == | |||
== Intern == | == Intern == | ||
== Weblinks == | == Weblinks == | ||
[[ | =Kontrollfragen= | ||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
''Testfrage 1'' | |||
<div class="mw-collapsible-content">'''Antwort1'''</div> | |||
</div> | |||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
''Testfrage 2'' | |||
<div class="mw-collapsible-content">'''Antwort2'''</div> | |||
</div> | |||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
''Testfrage 3'' | |||
<div class="mw-collapsible-content">'''Antwort3'''</div> | |||
</div> | |||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
''Testfrage 4'' | |||
<div class="mw-collapsible-content">'''Antwort4'''</div> | |||
</div> | |||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
''Testfrage 5'' | |||
<div class="mw-collapsible-content">'''Antwort5'''</div> | |||
</div> | |||
[[Kategorie:Bash/Konfiguration]] |
Aktuelle Version vom 6. November 2024, 12:33 Uhr
bash-completion erweitert die Vervollständigung von Befehlszeilen mit Hilfe der TAB-Taste
Installation
# apt install bash-completion
Aktivierung
Aktivierung für alle Benutzer
/etc/bash.bashrc
if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
Aktivierung pro Benutzer
~/.bashrc
if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
To try it without logging out and back in, run:
$ . ~/.bashrc
Funktionsweise
- the . in front of /etc/bash_completion does not refer to the current directory, since it has spaces around it.
- It instead makes the contents of the given file be evaluated in the currently running shell, instead of being executed in a new subshell. It is standardized here.
- In Bash, this . can be replaced by the command source, but this is not standardized by POSIX and is less portable so I tend to steer people away from using it.
- In this case, since it is specifically a program for extending bash, rather than something that needs to work in a bourne shell or ksh, you can feel free to substitute source for readability.
- Incidentally, this behavior (not opening a sub-shell) is similar to the way DOS/Windows .BAT scripts work normally, changing the state of the shell they are run in.
- This is why if you cd into a different path in a shell script, you won't be in that path when the script exits like you would be in a .BAT.
Anwendung
- Then try to use tab-completion
- That dot and space at the beginning (.) is the same as using the source keyword in bash, but is more portable.
- If you want it to work when su'd into the root account, do the same thing in root's home directory (typically /root).
Links
Dateien
Man-Page
Intern
Weblinks
Kontrollfragen
Testfrage 1
Antwort1
Testfrage 2
Antwort2
Testfrage 3
Antwort3
Testfrage 4
Antwort4
Testfrage 5
Antwort5