Quote alias values in the output of the alias(1) builtin so they are
suitable for re-input to the shell (SUSv3)
This commit is contained in:
parent
4ffc41abdd
commit
e5341cbb17
@ -207,8 +207,11 @@ aliascmd(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < ATABSIZE; i++)
|
||||
for (ap = atab[i]; ap; ap = ap->next) {
|
||||
if (*ap->name != '\0')
|
||||
out1fmt("alias %s=%s\n", ap->name, ap->val);
|
||||
if (*ap->name != '\0') {
|
||||
out1fmt("alias %s=", ap->name);
|
||||
out1qstr(ap->val);
|
||||
out1c('\n');
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@ -217,8 +220,11 @@ aliascmd(int argc, char **argv)
|
||||
if ((ap = lookupalias(n, 0)) == NULL) {
|
||||
outfmt(out2, "alias: %s not found\n", n);
|
||||
ret = 1;
|
||||
} else
|
||||
out1fmt("alias %s=%s\n", n, ap->val);
|
||||
} else {
|
||||
out1fmt("alias %s=", n);
|
||||
out1qstr(ap->val);
|
||||
out1c('\n');
|
||||
}
|
||||
else {
|
||||
*v++ = '\0';
|
||||
setalias(n, v);
|
||||
|
@ -107,6 +107,11 @@ out1str(const char *p)
|
||||
outstr(p, out1);
|
||||
}
|
||||
|
||||
void
|
||||
out1qstr(const char *p)
|
||||
{
|
||||
outqstr(p, out1);
|
||||
}
|
||||
|
||||
void
|
||||
out2str(const char *p)
|
||||
@ -114,6 +119,11 @@ out2str(const char *p)
|
||||
outstr(p, out2);
|
||||
}
|
||||
|
||||
void
|
||||
out2qstr(const char *p)
|
||||
{
|
||||
outqstr(p, out2);
|
||||
}
|
||||
|
||||
void
|
||||
outstr(const char *p, struct output *file)
|
||||
@ -124,10 +134,31 @@ outstr(const char *p, struct output *file)
|
||||
flushout(file);
|
||||
}
|
||||
|
||||
/* Like outstr(), but quote for re-input into the shell. */
|
||||
void
|
||||
outqstr(const char *p, struct output *file)
|
||||
{
|
||||
char ch;
|
||||
|
||||
out1c('\'');
|
||||
while ((ch = *p++) != '\0') {
|
||||
switch (ch) {
|
||||
case '\'':
|
||||
/*
|
||||
* Can't quote single quotes inside single quotes;
|
||||
* close them, write escaped single quote, open again.
|
||||
*/
|
||||
outstr("'\\''", file);
|
||||
break;
|
||||
default:
|
||||
outc(ch, file);
|
||||
}
|
||||
}
|
||||
out1c('\'');
|
||||
}
|
||||
|
||||
char out_junk[16];
|
||||
|
||||
|
||||
void
|
||||
emptyoutbuf(struct output *dest)
|
||||
{
|
||||
|
@ -1268,6 +1268,8 @@ With no arguments, the
|
||||
builtin command prints the names and values of all defined aliases
|
||||
(see
|
||||
.Ic unalias ) .
|
||||
Alias values are written with appropriate quoting so that they are
|
||||
suitable for reinput to the shell.
|
||||
.It Ic bg Op Ar job ...
|
||||
Continue the specified jobs
|
||||
(or the current job if no jobs are given)
|
||||
|
Loading…
x
Reference in New Issue
Block a user