diff --git a/check.t b/check.t index 3e7fd2b..f669b0c 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.546 2012/06/28 20:04:01 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.547 2012/06/28 20:05:05 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -4085,9 +4085,11 @@ description: (so quotes could also be used to hide hem). The former is easier, the later better... stdin: - echo $(echo \() + echo $(echo \( ) + echo $(echo "(" ) expected-stdout: ( + ( --- name: regression-9 description: @@ -6395,6 +6397,17 @@ expected-stdout: source='PATH=$PATH:. command .' type='whence -v' --- +name: aliases-cmdline +description: + Check that aliases work from the command line (Debian #517009) + Note that due to the nature of the lexing process, defining + aliases in COMSUBs then immediately using them, and things + like 'alias foo=bar && foo', still fail. +stdin: + "$__progname" -c $'alias a="echo OK"\na' +expected-stdout: + OK +--- name: aliases-funcdef-1 description: Check if POSIX functions take precedences over aliases diff --git a/lex.c b/lex.c index 4ac388a..cd8bdfb 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.163 2012/05/04 22:44:33 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.164 2012/06/28 20:05:07 tg Exp $"); /* * states while lexing word @@ -1283,6 +1283,7 @@ getsc_uu(void) break; case SSTRING: + case SSTRINGCMDLINE: break; case SWORDS: diff --git a/main.c b/main.c index 3ebbbfd..ebae37b 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.223 2012/06/24 20:15:47 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.224 2012/06/28 20:05:08 tg Exp $"); extern char **environ; @@ -461,7 +461,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) /* auto-detect from environment variables, always */ utf_flag = 3; } else if (Flag(FCOMMAND)) { - s = pushs(SSTRING, ATEMP); + s = pushs(SSTRINGCMDLINE, ATEMP); if (!(s->start = s->str = argv[argi++])) errorf("%s %s", "-c", "requires an argument"); #ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT diff --git a/mksh.1 b/mksh.1 index 09b608d..f8b3edb 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.286 2012/06/25 16:22:59 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.287 2012/06/28 20:05:09 tg Exp $ .\" $OpenBSD: ksh.1,v 1.143 2012/06/19 16:41:00 jmc Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -74,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: June 25 2012 $ +.Dd $Mdocdate: June 28 2012 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -1068,6 +1068,12 @@ space or tab, the following word is also checked for alias expansion. The alias expansion process stops when a word that is not an alias is found, when a quoted word is found, or when an alias word that is currently being expanded is found. +Aliases are specifically an interactive feature: while they do happen +to work in scripts and on the command line in some cases, aliases are +expanded during lexing, so their use must be in a separate command tree +from their definition; otherwise, the alias will not be found. +Noticeably, command lists (separated by semicolon, in command substitutions +also by newline) may be one same parse tree. .Pp The following command aliases are defined automatically by the shell: .Bd -literal -offset indent diff --git a/sh.h b/sh.h index b3812b8..cefebee 100644 --- a/sh.h +++ b/sh.h @@ -157,7 +157,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.566 2012/06/28 20:02:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.567 2012/06/28 20:05:11 tg Exp $"); #endif #define MKSH_VERSION "R40 2012/06/26" @@ -1462,6 +1462,7 @@ struct source { #define SWORDSEP 6 /* string[] separator */ #define SALIAS 7 /* alias expansion */ #define SREREAD 8 /* read ahead to be re-scanned */ +#define SSTRINGCMDLINE 9 /* string from "mksh -c ..." */ /* Source.flags values */ #define SF_ECHO BIT(0) /* echo input to shlout */