add aliases
- alias name=value defines aliases, alias lists or shows them in a form that can be read back, unalias removes them (unalias -a: all) - the first word of every command (at the start and after ;, &, &&, || and |) is replaced, the value is expanded again except for aliases that are already being expanded (alias ls='ls --color' works) - a value ending with a blank makes the next word a command name too - quoted or escaped words (\ll, 'll') skip the alias - aliases are only expanded in interactive shells and their startup files, like in bash - tab completion includes aliases Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dae4087a94
commit
187de30351
4 files changed
+422
-15
No files matched your search
@@ -17,6 +17,8 @@ Built-in commands:
|
||||
fg [%n] - Continue job n (default: current job) in the foreground
|
||||
bg [%n] - Continue stopped job n in the background
|
||||
wait [%n] - Wait for job n or all background jobs
|
||||
alias [name[=value] ...] - Define or show aliases (alias ll='ls -l')
|
||||
unalias name - Remove an alias (unalias -a: all aliases)
|
||||
help - Show this help
|
||||
|
||||
Features:
|
||||
@@ -43,6 +45,8 @@ Features:
|
||||
2>> file, 2>&1, >&2, &> file (stdout and stderr), &>> file
|
||||
- Job control: command & runs in the background, Ctrl+Z stops the
|
||||
foreground job; jobs, fg, bg and wait manage the jobs
|
||||
- Aliases replace the first word of a command in interactive shells
|
||||
(define them in ~/.goshrc); \name or 'name' skips the alias
|
||||
- Non-interactive use: gosh -c 'command', gosh script, command | gosh;
|
||||
the exit status is the one of the last command
|
||||
- Startup files: login shells (-l or argv[0] starting with -) read
|
||||
@@ -96,6 +100,10 @@ Beispiel für `~/.goshrc`:
|
||||
export PATH=$HOME/bin:$HOME/go/bin:$PATH
|
||||
export EDITOR=vim
|
||||
|
||||
# Aliase
|
||||
alias ll='ls -l'
|
||||
alias ..='cd ..'
|
||||
|
||||
# Prompt-Farben (Anführungszeichen wegen des ;)
|
||||
export GOSH_COLORS='user=1;38;5;208:path=38;5;205'
|
||||
|
||||
@@ -186,6 +194,34 @@ $ grep -c error < build.log
|
||||
- Der Exit-Status einer Pipeline ist der des letzten Befehls. Beendet sich ein Befehl am Ende (z. B. `head`), bekommt der schreibende Befehl davor `SIGPIPE`, `yes | head -1` endet also sofort.
|
||||
- Die Built-ins `pwd` und `help` lassen sich umleiten und in Pipes verwenden (`help | less`). `cd`, `set`, `export`, `exit` und `quit` verändern die Shell selbst und sind in einer Pipeline nicht erlaubt.
|
||||
|
||||
### Aliase
|
||||
|
||||
Ein Alias ist ein Kurzname für einen Befehl, am besten in `~/.goshrc` definiert:
|
||||
|
||||
```bash
|
||||
alias ll='ls -l'
|
||||
alias la='ls -la'
|
||||
alias ..='cd ..'
|
||||
alias gs='git status'
|
||||
alias ls='ls --color=auto' # ein Alias darf den eigenen Namen enthalten
|
||||
alias please='sudo ' # endet mit Leerzeichen: das nächste Wort wird auch ersetzt
|
||||
```
|
||||
|
||||
| Befehl | Bedeutung |
|
||||
|-------------------------|---------------------------------------------------|
|
||||
| `alias name='wert'` | definiert einen Alias (mehrere in einem Aufruf möglich) |
|
||||
| `alias` | listet alle Aliase (in einer Form, die sich wieder einlesen lässt) |
|
||||
| `alias name` | zeigt einen Alias |
|
||||
| `unalias name` | entfernt einen Alias, `unalias -a` alle |
|
||||
|
||||
- Ersetzt wird nur das erste Wort eines Befehls, also am Zeilenanfang und nach `;`, `&&`, `||`, `|` und `&`: `ll | less` funktioniert, `echo ll` gibt `ll` aus.
|
||||
- Der Wert darf selbst mehrere Befehle enthalten (`alias up='cd .. && ls'`) und wird wiederum auf Aliase geprüft. Ein Alias, der gerade ersetzt wird, wird darin nicht noch einmal ersetzt, deshalb funktioniert `alias ls='ls --color=auto'`.
|
||||
- Endet der Wert mit einem Leerzeichen, wird auch das nächste Wort als Alias geprüft: Mit den Aliasen oben wird `please ll` zu `sudo ls --color=auto -l`.
|
||||
- Mit `\ll` oder `'ll'` umgeht man den Alias und ruft das Programm direkt auf.
|
||||
- Aliase gelten nur in interaktiven Shells (wie in bash), also auch in `~/.goshrc`, aber nicht in Skripten und bei `gosh -c`. Ein Alias wirkt erst ab der nächsten Zeile, nicht in der Zeile, in der er definiert wird.
|
||||
- Erlaubt sind Namen aus Buchstaben, Ziffern und `_ - . + : , @ % ^`.
|
||||
- Aliase werden auch mit Tab vervollständigt.
|
||||
|
||||
### Job-Control
|
||||
|
||||
In einer interaktiven Shell läuft jede Befehlszeile (bzw. jede Pipeline) als eigener *Job* in einer eigenen Prozessgruppe:
|
||||
|
||||
Reference in new issue
Block a user