--- eval.c (revision 350485) +++ eval.c (working copy) @@ -78,8 +78,8 @@ static int loopnest; /* current loop nesting level */ int funcnest; /* depth of function calls */ static int builtin_flags; /* evalcommand flags for builtins */ +static int elinno; - char *commandname; struct arglist *cmdenviron; int exitstatus; /* exit status of last command */ @@ -809,6 +809,11 @@ return (0); } +int getelinno() +{ + return elinno; +} + /* * Execute a simple command. * Note: This may or may not return if (flags & EV_EXIT). @@ -853,6 +858,7 @@ /* Add one slot at the beginning for tryexec(). */ appendarglist(&arglist, nullstr); for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { + elinno = argp->narg.linno; if (varflag && isassignment(argp->narg.text)) { expandarg(argp, varflag == 1 ? &varlist : &arglist, EXP_VARTILDE); --- eval.h (revision 350485) +++ eval.h (working copy) @@ -57,6 +57,7 @@ union node; /* BLETCH for ansi C */ void evaltree(union node *, int); void evalbackcmd(union node *, struct backcmd *); +int getelinno(); /* in_function returns nonzero if we are currently evaluating a function */ #define in_function() funcnest --- nodetypes (revision 350485) +++ nodetypes (working copy) @@ -108,6 +108,7 @@ NARG narg # represents a word type int + linno int next nodeptr # next word in list text string # the text of the word backquote nodelist # list of commands in back quotes --- parser.c (revision 350485) +++ parser.c (working copy) @@ -704,6 +704,10 @@ n = (union node *)stalloc(sizeof (struct narg)); n->type = NARG; + if (funclinno) + n->narg.linno = plinno - funclinno; + else + n->narg.linno = plinno; n->narg.next = NULL; n->narg.text = wordtext; n->narg.backquote = backquotelist; @@ -1664,7 +1668,7 @@ CHECKSTRSPACE(11, out); linno = plinno; if (funclinno != 0) - linno -= funclinno - 1; + linno -= funclinno; length = snprintf(out, 11, "%d", linno); if (length > 10) length = 10; --- var.c (revision 350485) +++ var.c (working copy) @@ -429,6 +429,13 @@ { struct var *v; + if (strcmp("LINENO", name) == 0) { + static char buf[11]; + bzero(buf, 11); + snprintf(buf, 11, "%d", getelinno()); + return buf; + } + v = find_var(name, NULL, NULL); if (v == NULL || v->flags & VUNSET) return NULL;