Implement `set +o', which displays the currently set options in a format

suitable for re-input into the shell.
This commit is contained in:
Tim J. Robbins 2002-05-25 12:11:58 +00:00
parent ba545bbb61
commit d513af6a66
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97276
2 changed files with 28 additions and 5 deletions

View File

@ -200,13 +200,28 @@ options(int cmdline)
STATIC void
minus_o(char *name, int val)
{
int i;
int doneset, i;
if (name == NULL) {
out1str("Current option settings\n");
for (i = 0; i < NOPTS; i++)
out1fmt("%-16s%s\n", optlist[i].name,
optlist[i].val ? "on" : "off");
if (val) {
/* "Pretty" output. */
out1str("Current option settings\n");
for (i = 0; i < NOPTS; i++)
out1fmt("%-16s%s\n", optlist[i].name,
optlist[i].val ? "on" : "off");
} else {
/* Output suitable for re-input to shell. */
for (doneset = i = 0; i < NOPTS; i++)
if (optlist[i].val) {
if (!doneset) {
out1str("set");
doneset = 1;
}
out1fmt(" -o %s", optlist[i].name);
}
if (doneset)
out1c('\n');
}
} else {
for (i = 0; i < NOPTS; i++)
if (equal(name, optlist[i].name)) {

View File

@ -301,6 +301,14 @@ command line editor:
set -E
set -o emacs
.Ed
.Pp
If used without an argument, the
.Fl o
option displays the current option settings in a human-readable format.
If
.Cm +o
is used without an argument, the current option settings are output
in a format suitable for re-input into the shell.
.Ss Lexical Structure
The shell reads input in terms of lines from a file and breaks
it up into words at whitespace (blanks and tabs), and at