add subshells, here-documents and redirections/pipes for control structures
- control structures can have redirections (while read l; do ...; done
< file), which apply to all commands in them; they run in the shell
- in pipes and in the background they run in a subshell (cmd | while
read l; do ...; done, for ...; done &, a && b &)
- ( list ) subshells; ( and ) are operators now
- here-documents <<EOF, <<-EOF, <<'EOF' and here-strings <<<word
- redirections of source apply to the commands of the file
- fix non-ASCII characters in quotes being mangled ('für')
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
443367f66f
commit
f66cf538c0
7 files changed
+1172
-221
No files matched your search
+38
-4
@@ -320,6 +320,24 @@ Redirect standard output to where standard error goes.
|
||||
.BR &> " \fIfile\fP, " &>> " \fIfile\fP"
|
||||
Write (or append) standard output and standard error to
|
||||
.IR file .
|
||||
.TP
|
||||
.BI << word
|
||||
Here-document: the lines after the command, up to a line that is exactly
|
||||
.IR word ,
|
||||
are standard input. If no part of
|
||||
.I word
|
||||
is quoted, variables, command substitutions and backslashes before
|
||||
.BR $ ,
|
||||
.BR \(ga ,
|
||||
.B \e
|
||||
and newline are expanded in the lines.
|
||||
.BI <<\- word
|
||||
also removes leading tabs from the lines and the delimiter line.
|
||||
.TP
|
||||
.BI <<< " word"
|
||||
Here-string:
|
||||
.I word
|
||||
and a newline are standard input.
|
||||
.PP
|
||||
Redirections are evaluated from left to right. Only file descriptors 0, 1
|
||||
and 2 are supported.
|
||||
@@ -331,6 +349,7 @@ and 2 are supported.
|
||||
\fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP
|
||||
\fBcase\fP \fIword\fP \fBin\fP [\fB(\fP]\fIpattern\fP[\fB|\fP\fIpattern\fP]...\fB)\fP \fIlist\fP \fB;;\fP ... \fBesac\fP
|
||||
\fB{\fP \fIlist\fP; \fB}\fP
|
||||
\fB(\fP \fIlist\fP \fB)\fP
|
||||
\fB!\fP \fIcommand\fP
|
||||
.fi
|
||||
.PP
|
||||
@@ -362,11 +381,23 @@ of the last clause may be omitted.
|
||||
.IR list ;
|
||||
.B }
|
||||
groups commands; they run in the current shell.
|
||||
.B (
|
||||
.I list
|
||||
.B )
|
||||
runs the commands in a subshell, a new
|
||||
.B gosh
|
||||
process, so that changes of the directory, variables and functions only
|
||||
apply there.
|
||||
.PP
|
||||
Control structures cannot be used in pipes, with redirections or in the
|
||||
background, and there are no
|
||||
.B ( ... )
|
||||
subshells.
|
||||
Redirections after a control structure
|
||||
.RB ( "done < file" ,
|
||||
.BR "fi > log 2>&1" )
|
||||
apply to all commands in it, which still run in the current shell. In a
|
||||
pipe and in the background
|
||||
.RB ( & ),
|
||||
a control structure runs in a subshell, like in
|
||||
.BR sh (1).
|
||||
The subshell knows the functions and positional parameters of the shell.
|
||||
.SS Functions
|
||||
.nf
|
||||
\fIname\fP\fB() {\fP \fIlist\fP; \fB}\fP
|
||||
@@ -631,6 +662,9 @@ make > build.log 2>&1 || echo "failed: $?"
|
||||
LANG=C sort file
|
||||
alias ll=\(aqls \-l\(aq
|
||||
greet() { echo "Hello ${1:\-World}"; }
|
||||
git ls\-files | while read \-r f; do wc \-l "$f"; done
|
||||
while read \-r user rest; do echo "$user"; done < /etc/passwd
|
||||
(cd build && make) > build.log 2>&1
|
||||
case "$1" in start|stop) echo "$1ing" ;; *) echo "usage: $0 start|stop" ;; esac
|
||||
read \-r \-p \(aqName? \(aq name
|
||||
chsh \-s /usr/bin/gosh
|
||||
|
||||
Reference in new issue
Block a user