Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Implement:
details: https://anonhg.NetBSD.org/src/rev/652463a9c34c
branches: trunk
changeset: 995225:652463a9c34c
user: kre <kre%NetBSD.org@localhost>
date: Wed Dec 12 11:51:33 2018 +0000
description:
Implement:
readonly -q VAR...
readonly -p VAR...
export -q [-x] VAR...
export -p [-x] VAR...
all available only in !SMALL shells - and while here, limit
"export -x" to full sized shells as well.
Also, do a better job of arg checking and validating of the
export and readonly commands (which is really just one built-in)
and of issuing error messages when something bogus is detected.
Since these commands are special builtin commands, any error
causes shell exit (for non-interactive shells).
diffstat:
bin/sh/sh.1 | 123 ++++++++++++++++++++++++++++++++++-----
bin/sh/var.c | 179 +++++++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 242 insertions(+), 60 deletions(-)
diffs (truncated from 619 to 300 lines):
diff -r 9f21d292c8bc -r 652463a9c34c bin/sh/sh.1
--- a/bin/sh/sh.1 Wed Dec 12 11:40:08 2018 +0000
+++ b/bin/sh/sh.1 Wed Dec 12 11:51:33 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sh.1,v 1.212 2018/12/11 13:31:20 kre Exp $
+.\" $NetBSD: sh.1,v 1.213 2018/12/12 11:51:33 kre Exp $
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,7 +31,7 @@
.\"
.\" @(#)sh.1 8.6 (Berkeley) 5/4/95
.\"
-.Dd December 11, 2018
+.Dd December 12, 2018
.Dt SH 1
.\" everything except c o and s (keep them ordered)
.ds flags abCEeFfhIiLmnpquVvXx
@@ -2274,6 +2274,7 @@
.It Ic \&: Op Ar arg ...
A null command that returns a 0 (true) exit value.
Any arguments or redirects are evaluated, then ignored.
+.\"
.It Ic \&. Ar file
The dot command reads and executes the commands from the specified
.Ar file
@@ -2293,6 +2294,7 @@
This implementation allows them to control loops surrounding the dot command,
but obviously such behavior should not be relied on.
It is now permitted by the standard, but not required.
+.\"
.It Ic alias Op Ar name Ns Op Li = Ns Ar string ...
If
.Ar name Ns Li = Ns Ar string
@@ -2310,9 +2312,11 @@
built-in prints the
names and values of all defined aliases (see
.Ic unalias ) .
+.\"
.It Ic bg Op Ar job ...
Continue the specified jobs (or the current job if no
jobs are given) in the background.
+.\"
.It Ic command Oo Fl pVv Oc Ar command Op Ar arg ...
Execute the specified command but ignore shell functions when searching
for it.
@@ -2335,6 +2339,7 @@
search for the command and print the absolute pathname
of utilities, the name for built-ins or the expansion of aliases.
.El
+.\"
.It Ic cd Oo Fl P Oc Op Ar directory Op Ar replace
Switch to the specified directory (default
.Ev $HOME ) .
@@ -2402,9 +2407,11 @@
or if the
.Ar replace
argument was used.
+.\"
.It Ic eval Ar string ...
Concatenate all the arguments with spaces.
Then re-parse and execute the command.
+.\"
.It Ic exec Op Ar command Op Ar arg ...
Unless
.Ar command
@@ -2447,14 +2454,17 @@
.Ic fdflags
command below, which can set, or clear, this, and other,
file descriptor flags.
+.\"
.It Ic exit Op Ar exitstatus
Terminate the shell process.
If
.Ar exitstatus
is given it is used as the exit status of the shell; otherwise the
exit status of the preceding command (the current value of $?) is used.
-.It Ic export Oo Fl npx Oc Ar name ...
-.It Ic export Fl p Op Fl x
+.\"
+.It Ic export Oo Fl nx Oc Ar name Ns Oo =value Oc ...
+.It Ic export Oo Fl x Oc Oo Fl p Oo Ar name ... Oc Oc
+.It Ic export Fl q Oo Fl x Oc Ar name ...
With no options,
but one or more names,
the specified names are exported so that they will appear in the
@@ -2477,6 +2487,7 @@
That is
.Bd -literal -offset indent
export -x FOO # FOO will now not be exported by default
+export FOO # this command will fail (non-fatally)
FOO=some_value my_command
.Ed
.Pp
@@ -2487,30 +2498,57 @@
through the environment.
.Pp
The shell allows the value of a variable to be set at the
-same time it is exported by writing
+same time it is exported (or unexported, etc) by writing
.Pp
-.Dl export name=value
+.Dl export [-nx] name=value
.Pp
-With no arguments the export command lists the names of all exported variables,
+With no arguments the export command lists the names of all
+set exported variables,
or if
.Fl x
-was given, all variables marked not for export.
+was given, all set variables marked not for export.
With the
.Fl p
-option specified the output will be formatted suitably for non-interactive use.
+option specified, the output will be formatted suitably for
+non-interactive use, and unset variables are included.
+When
+.Fl p
+is given, variable names, but not values, may also be
+given, in which case output is limited to the variables named.
.Pp
-The
+With
+.Fl q
+and a list of variable names, the
+.Ic export
+command will exit with status 0 if all the named
+variables have been marked for export, or 1 if
+any are not so marked.
+If
+.Fl x
+is also given,
+the test is instead for variables marked not to be exported.
+.Pp
+Other than with
+.Fl q ,
+the
.Ic export
built-in exits with status 0,
-unless an invalid option, or option combination, is given,
-or unless an attempt is made to export a variable which has
+unless an attempt is made to export a variable which has
been marked as unavailable for export,
in which cases it exits with status 1.
+In all cases if
+an invalid option, or option combination, is given,
+or an invalid variable name is present,
+.Ic export
+will write a message to the standard error output,
+and exit with a non-zero status.
+A non-interactive shell will terminate.
.Pp
Note that there is no restriction upon exporting,
or un-exporting, read-only variables.
The no-export flag can be reset by unsetting the variable
-and creating it again \(en provided it is not also read-only.
+and creating it again \(en provided the variable is not also read-only.
+.\"
.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last
.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last
.It Ic fc Fl s Oo Ar old=new Oc Op Ar first
@@ -2602,10 +2640,12 @@
.It Ev HISTSIZE
The number of previous commands that are accessible.
.El
+.\"
.It Ic fg Op Ar job
Move the specified job or the current job to the foreground.
A foreground job can interact with the user via standard input,
and receive signals from the terminal.
+.\"
.It Ic fdflags Oo Fl v Oc Op Ar fd ...
.It Ic fdflags Oo Fl v Oc Fl s Ar flags fd Op ...
Get or set file descriptor flags.
@@ -2642,6 +2682,7 @@
and
.Xr open 2
for more information.
+.\"
.It Ic getopts Ar optstring var
The POSIX
.Ic getopts
@@ -2742,6 +2783,7 @@
cmd \-carg -a file file
cmd \-a \-carg \-\- file file
.Ed
+.\"
.It Ic hash Oo Fl rv Oc Op Ar command ...
The shell maintains a hash table which remembers the
locations of commands.
@@ -2765,11 +2807,13 @@
.Fl r
option causes the hash command to delete all the entries in the hash table
except for functions.
+.\"
.It Ic inputrc Ar file
Read the
.Ar file
to set key bindings as defined by
.Xr editrc 5 .
+.\"
.It Ic jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job
With no flags, print the process identifiers of the processes in the job.
If the
@@ -2815,6 +2859,7 @@
.Fl p
there is no process group leader (should not happen),
and otherwise exits with status 0.
+.\"
.It Ic jobs Oo Fl l Ns \&| Ns Fl p Oc Op Ar job ...
Without
.Ar job
@@ -2856,6 +2901,7 @@
Non-interactive shells need to execute
.Ic wait
commands to clean up terminated background jobs.
+.\"
.It Ic local Oo Fl INx Oc Oo Ar variable | \- Oc ...
Define local variables for a function.
Local variables have their attributes, and values,
@@ -3050,6 +3096,7 @@
below for details of the effects of making the variable
.Dv LINENO
local.
+.\"
.It Ic pwd Op Fl \&LP
Print the current directory.
If
@@ -3090,6 +3137,7 @@
the program will use
.Ev PWD
and the built-in uses a separately cached value.
+.\"
.It Ic read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ...
The
.Ar prompt
@@ -3120,9 +3168,12 @@
literally.
If a backslash is followed by a newline, the backslash and the
newline will be deleted.
-.It Ic readonly Ar name ...
-.It Ic readonly Op Fl p
-The specified names are marked as read only, so that they cannot be
+.\"
+.It Ic readonly Ar name Ns Oo =value Oc Ns ...
+.It Ic readonly Oo Fl p Op name... Oc
+.It Ic readonly Oo Fl q Oc name...
+With no options,
+the specified names are marked as read only, so that they cannot be
subsequently modified or unset.
The shell allows the value of a variable
to be set at the same time it is marked read only by writing
@@ -3131,10 +3182,38 @@
.Pp
With no arguments the
.Ic readonly
-command lists the names of all read only variables.
+command lists the names of all set read only variables.
With the
.Fl p
-option specified the output will be formatted suitably for non-interactive use.
+option specified,
+the output will be formatted suitably for non-interactive use,
+and unset variables are included.
+When the
+.Fl p
+option is given,
+a list of variable names (without values) may also be specified,
+in which case output is limited to the named variables.
+.Pp
+With the
+.Fl q
+option, the
+.Ic readonly
+command tests the read-only status of the variables listed
+and exits with status 0 if all named variables are read-only,
+or with status 1 if any are not read-only.
+.Pp
+Other than as specified for
+.Fl q
+the
+.Ic readonly
+command normally exits with status 0.
+In all cases, if an unknown option, or an invalid option combination,
+or an invalid variable name, is given;
+or a variable which was already read-only is attempted to be set;
+the exit status will not be zero, a diagnostic
+message will be written to the standard error output,
+and a non-interactive shell will terminate.
+.\"
.It Ic return Op Ar n
Stop executing the current function or a dot command with return value of
.Ar n
@@ -3152,6 +3231,7 @@
.Ic exit
command instead, if you want to return from a script or exit
your shell.
+.\"
.It Ic set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ...
The
Home |
Main Index |
Thread Index |
Old Index