Bash/bash-completion: Unterschied zwischen den Versionen

Aus Foxwiki
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:


= Aktivierung =
= Aktivierung =
bash-completion kann pro Benutzer oder global für alle Benutzer aktiviert werden
== Aktivierung pro Benutzer ==
== Aktivierung pro Benutzer ==
~/.bashrc
~/.bashrc
Zeile 16: Zeile 14:
         fi
         fi
     fi
     fi
* To try it without logging out and back in, run:
* To try it without logging out and back in, run:
  . ~/.bashrc
  . ~/.bashrc
* Or open a new shell.  
* Or open a new shell.  
* Then try to use tab-completion
* Then try to use tab-completion
Zeile 24: Zeile 24:


== Aktivierung für alle Benutzer ==
== Aktivierung für alle Benutzer ==
* Do changes from (2.1) in /etc/bash.bashrc
/etc/bash.bashrc
* To anyone who's wondering why this works, the . in front of /etc/bash_completion does not refer to the current directory, since it has spaces around it.  
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
 
=== Why this works ===
* 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.
* 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 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.  
Zeile 31: Zeile 40:
* 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.  
* 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.
* 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.
== Anwendungen ==
== Anwendungen ==
* TODO
TODO


= Links =
= Links =
== Interne Links ==
== Intern ==
# TODO
# TODO
== Externe Links ==
== Weblinks ==
# TODO
# TODO


[[Category:Linux:Bash]]
[[Category:Linux:Bash]]

Version vom 26. September 2020, 08:11 Uhr

bash-completion erweitert die Vervollständigung von Befehlszeilen mit Hilfe der TAB-Taste

Installation

apt install bash-completion

Aktivierung

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
  • Or open a new shell.
  • 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).

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

Why this works

  • 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.

Anwendungen

TODO

Links

Intern

  1. TODO

Weblinks

  1. TODO