sh: Properly quote alias output from command -v.

An alias should be printed by command -v as a command line; therefore, make
the alias definition suitable for re-input to the shell.
This commit is contained in:
Jilles Tjoelker 2013-11-10 23:00:39 +00:00
parent 48f22b9682
commit 5d4d10e3e5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=257929
2 changed files with 12 additions and 3 deletions

View File

@ -672,9 +672,11 @@ typecmd_impl(int argc, char **argv, int cmd, const char *path)
/* Then look at the aliases */
if ((ap = lookupalias(argv[i], 1)) != NULL) {
if (cmd == TYPECMD_SMALLV)
out1fmt("alias %s='%s'\n", argv[i], ap->val);
else
if (cmd == TYPECMD_SMALLV) {
out1fmt("alias %s=", argv[i]);
out1qstr(ap->val);
outcslow('\n', out1);
} else
out1fmt("%s is an alias for %s\n", argv[i],
ap->val);
continue;

View File

@ -0,0 +1,7 @@
# $FreeBSD$
alias aa=echo\ \'\"\'
cmd=$(command -v aa)
alias aa=echo\ bad
eval "$cmd"
[ "$(eval aa)" = \" ]