add command lists (;, &&, ||) and $?
- split input at unquoted ;, && and || and run the commands like sh;
variables are expanded per command when it runs
- $? and ${?} expand to the exit status of the last command,
exit/quit without argument use it
- syntax errors for missing commands around operators (status 2)
- "command not found" message instead of the raw exec error, no more
"exit status N" message when a command fails
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b602e17622
commit
f5c14dff90
3 files changed
+307
-20
No files matched your search
@@ -8,8 +8,8 @@ Built-in commands:
|
||||
cd [dir] - Change directory (cd with no args goes to home)
|
||||
pwd - Print working directory
|
||||
echo [args] - Echo arguments
|
||||
exit [code] - Exit shell with optional status code
|
||||
quit [code] - Quit shell with optional status code
|
||||
exit [code] - Exit shell with status code (default: $?)
|
||||
quit [code] - Quit shell with status code (default: $?)
|
||||
set VAR=val - Set environment variable
|
||||
export VAR=val - Export environment variable
|
||||
help - Show this help
|
||||
@@ -29,6 +29,8 @@ Features:
|
||||
disabled with $NO_COLOR, TERM=dumb or when output is not a terminal
|
||||
- Environment variable expansion ($VAR, ${VAR}, ${VAR:-default});
|
||||
using an unset variable is an error, use ${VAR:-} for an empty default
|
||||
- Command lists: a ; b (run both), a && b (b only if a succeeded),
|
||||
a || b (b only if a failed); $? is the exit status of the last command
|
||||
- Non-interactive use: gosh -c 'command', gosh script, command | gosh;
|
||||
the exit status is the one of the last command
|
||||
|
||||
@@ -53,7 +55,31 @@ gosh -version
|
||||
|
||||
Ohne Terminal bricht gosh bei einem fehlgeschlagenen Befehl nicht ab und beendet sich mit dem Exit-Status des letzten Befehls: `127`, wenn ein Befehl nicht gefunden wurde, `126`, wenn er nicht ausführbar ist, `128+n`, wenn er durch Signal `n` beendet wurde. Leere Zeilen und Zeilen, die mit `#` beginnen, werden übersprungen, Skripte können also mit `#!/usr/bin/gosh` beginnen.
|
||||
|
||||
Damit funktionieren auch `ssh host befehl`, `scp` und `rsync`, wenn gosh als Login-Shell gesetzt ist. Da gosh `;`, `&&` und Pipes noch nicht kennt, darf der Befehl dabei aber nur aus einem einfachen Kommando bestehen.
|
||||
Damit funktionieren auch `ssh host befehl`, `scp` und `rsync`, wenn gosh als Login-Shell gesetzt ist. Befehle lassen sich mit `;`, `&&` und `||` verketten (z. B. `ssh host 'cd /srv && git pull'`), Pipes und Umleitungen kennt gosh aber noch nicht.
|
||||
|
||||
### Befehlslisten und Exit-Status
|
||||
|
||||
Mehrere Befehle in einer Zeile werden wie in `sh` verknüpft:
|
||||
|
||||
| Liste | Bedeutung |
|
||||
|------------|---------------------------------------------------|
|
||||
| `a ; b` | erst `a`, dann `b` |
|
||||
| `a && b` | `b` nur, wenn `a` erfolgreich war (Exit-Status 0) |
|
||||
| `a \|\| b` | `b` nur, wenn `a` fehlgeschlagen ist |
|
||||
|
||||
`&&` und `||` werden von links nach rechts ausgewertet, `a && b || c` führt also `c` aus, wenn `a` oder `b` fehlschlägt. Variablen werden erst beim Ausführen des jeweiligen Befehls expandiert, `cd /tmp && echo $PWD` gibt also schon das neue Verzeichnis aus.
|
||||
|
||||
`$?` (bzw. `${?}`) enthält den Exit-Status des letzten Befehls, `exit` ohne Argument beendet gosh mit diesem Status:
|
||||
|
||||
```
|
||||
$ false; echo $?
|
||||
1
|
||||
$ gibtsnicht || echo "Status $?"
|
||||
gosh: gibtsnicht: command not found
|
||||
Status 127
|
||||
```
|
||||
|
||||
Schlägt ein Programm fehl, gibt gosh selbst keine Meldung mehr aus (das Programm meldet den Fehler selbst), nur bei Fehlern von gosh, z. B. wenn ein Befehl nicht gefunden wird.
|
||||
|
||||
### Farben
|
||||
|
||||
|
||||
Reference in new issue
Block a user