Lines Matching +full:set +full:- +full:job +full:- +full:env +full:- +full:vars
3 /*-
11 * is granted to deal in this work without restriction, including un-
71 if ((flags&XFORK) && !(flags&XEXEC) && t->type != TPIPE) in execute()
72 /* run in sub-process */ in execute()
73 return (exchild(t, flags & ~XTIME, xerrok, -1)); in execute()
80 if (t->type == TCOM) { in execute()
88 current_lineno = t->lineno; in execute()
93 t->args[0] == NULL && in execute()
95 t->vars[0] != NULL && t->vars[1] == NULL && in execute()
97 t->ioact != NULL && t->ioact[0] != NULL && in execute()
98 t->ioact[1] == NULL && in execute()
100 (t->ioact[0]->ioflag & IOTYPE) == IOHERE && in execute()
102 (ccp = skip_wdvarname(t->vars[0], true)) != t->vars[0] && in execute()
103 /* and has no right-hand side (i.e. "varname=") */ in execute()
109 if ((rv = herein(t->ioact[0], &cp) /*? 1 : 0*/)) in execute()
111 strdup2x(dp, evalstr(t->vars[0], DOASNTILDE | DOSCALAR), in execute()
124 up = eval(t->args, t->u.evalflags | DOBLANK | DOGLOB | DOTILDE); in execute()
134 if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) { in execute()
135 e->savefd = alloc2(NUFILE, sizeof(short), ATEMP); in execute()
137 memset(e->savefd, 0, NUFILE * sizeof(short)); in execute()
141 vp_pipest->flag |= INT_L; in execute()
144 if (t->ioact != NULL) in execute()
145 for (iowp = t->ioact; *iowp != NULL; iowp++) { in execute()
150 * cause (non-interactive) shell to exit. in execute()
152 if (tp && tp->type == CSHELL && in execute()
153 (tp->flag & SPEC_BI)) in execute()
160 switch (t->type) { in execute()
166 rv = execute(t->left, flags | XFORK, xerrok); in execute()
172 e->savefd[0] = savefd(0); in execute()
173 e->savefd[1] = savefd(1); in execute()
174 while (t->type == TPIPE) { in execute()
184 exchild(t->left, flags | XPIPEO | XCCLOSE, in execute()
190 t = t->right; in execute()
193 restfd(1, e->savefd[1]); in execute()
194 /* no need to re-restore this */ in execute()
195 e->savefd[1] = 0; in execute()
203 while (t->type == TLIST) { in execute()
204 execute(t->left, flags & XERROK, NULL); in execute()
205 t = t->right; in execute()
219 e->type = E_ERRH; in execute()
220 if ((i = kshsetjmp(e->jbuf))) { in execute()
227 /* Already have a (live) co-process? */ in execute()
228 if (coproc.job && coproc.write >= 0) in execute()
231 /* Can we re-use the existing co-process pipe? */ in execute()
235 e->savefd[0] = savefd(0); in execute()
236 e->savefd[1] = savefd(1); in execute()
244 coproc.job = NULL; in execute()
261 e->type = E_EXEC; in execute()
267 * job is actually created. in execute()
270 exchild(t->left, flags | XBGND | XFORK | XCOPROC | XCCLOSE, in execute()
277 * XXX non-optimal, I think - "(foo &)", forks for (), in execute()
281 rv = execute(t->left, (flags&~XEXEC)|XBGND|XFORK, xerrok); in execute()
286 rv = execute(t->left, XERROK, NULL); in execute()
287 if ((rv == 0) == (t->type == TAND)) in execute()
288 rv = execute(t->right, flags & XERROK, xerrok); in execute()
297 rv = !execute(t->right, XERROK, xerrok); in execute()
307 te.pos.wp = t->args; in execute()
321 ap = (t->vars == NULL) ? e->loc->argv + 1 : in execute()
322 (const char **)eval((const char **)t->vars, in execute()
324 e->type = E_LOOP; in execute()
325 while ((i = kshsetjmp(e->jbuf))) { in execute()
326 if ((e->flags&EF_BRKCONT_PASS) || in execute()
337 if (t->type == TFOR) { in execute()
339 setstr(global(t->str), *ap++, KSH_UNWIND_ERROR); in execute()
340 rv = execute(t->left, flags & XERROK, xerrok); in execute()
346 setstr(global(t->str), ccp, KSH_UNWIND_ERROR); in execute()
347 execute(t->left, flags & XERROK, xerrok); in execute()
357 e->type = E_LOOP; in execute()
358 while ((i = kshsetjmp(e->jbuf))) { in execute()
359 if ((e->flags&EF_BRKCONT_PASS) || in execute()
370 while ((execute(t->left, XERROK, NULL) == 0) == in execute()
371 (t->type == TWHILE)) in execute()
372 rv = execute(t->right, flags & XERROK, xerrok); in execute()
377 if (t->right == NULL) in execute()
380 rv = execute(execute(t->left, XERROK, NULL) == 0 ? in execute()
381 t->right->left : t->right->right, flags & XERROK, xerrok); in execute()
386 ccp = evalstr(t->str, DOTILDE | DOSCALAR); in execute()
387 for (t = t->left; t != NULL && t->type == TPAT; t = t->right) { in execute()
388 for (ap = (const char **)t->vars; *ap; ap++) { in execute()
392 rv = execute(t->left, flags & XERROK, in execute()
395 switch (t->u.charflag) { in execute()
413 rv = execute(t->left, flags & XERROK, xerrok); in execute()
417 rv = define(t->str, t); in execute()
423 * (allows "ls -l | time grep foo"). in execute()
434 if (!Flag(FPOSIX) && !Flag(FSH) && t->left->ioact != NULL) in execute()
435 for (iowp = t->left->ioact; *iowp != NULL; iowp++) in execute()
436 if ((*iowp)->ioflag & IODUPSELF) in execute()
437 fcntl((*iowp)->unit, F_SETFD, 0); in execute()
442 cargs.ro = t->args; in execute()
443 execve(t->str, cargs.rw, up); in execute()
449 errorfx(126, Tf_sD_s, t->str, cstrerror(rv)); in execute()
453 if (vp_pipest->flag & INT_L) { in execute()
455 vp_pipest->flag = DEFINED | ISSET | INTEGER | RDONLY | in execute()
457 vp_pipest->val.i = rv; in execute()
499 * XXX not the same as AT&T ksh, which only seems to set $_ in comexec()
501 * interactive and script) - perhaps save last arg here and in comexec()
502 * set it in shell()?. in comexec()
507 setstr(typeset("_", LOCAL, 0, INTEGER, 0), *--lastp, in comexec()
525 while (tp && tp->type == CSHELL) { in comexec()
528 if (tp->val.f == c_builtin) { in comexec()
530 (!strcmp(cp, "--") && (cp = *++ap) == NULL)) { in comexec()
536 if (tp->type == CSHELL && (tp->flag & LOW_BI)) in comexec()
539 } else if (tp->val.f == c_exec) { in comexec()
543 while ((optc = ksh_getopt(ap, &builtin_opt, "a:c")) != -1) in comexec()
559 /* POSuX demands ksh88-like behaviour here */ in comexec()
563 } else if (tp->val.f == c_command) { in comexec()
573 if (optc != -1) in comexec()
574 /* command -vV or something */ in comexec()
581 "command -p", "restricted"); in comexec()
599 } else if (tp->flag & LOW_BI) { in comexec()
601 if ((ap[1] && ap[1][0] == '-' && ap[1][1] != '\0' && in comexec()
602 /* argument, begins with -, is not - or -- */ in comexec()
603 (ap[1][1] != '-' || ap[1][2] != '\0')) || in comexec()
605 (tp->flag & LOWER_BI)) { in comexec()
608 ext_cmd = findcom(tp->name, FC_FUNC | FC_PATH); in comexec()
609 if (ext_cmd && (ext_cmd->type == CFUNC || in comexec()
610 (ext_cmd->flag & ISSET))) in comexec()
614 } else if (tp->val.f == c_trap) { in comexec()
615 t->u.evalflags &= ~DOTCOMEXEC; in comexec()
621 if (t->u.evalflags & DOTCOMEXEC) in comexec()
623 l_expand = e->loc; in comexec()
624 if (!resetspec && (!ap[0] || (tp && (tp->flag & KEEPASN)))) in comexec()
632 l_assign = e->loc; in comexec()
634 l_assign->flags |= BF_STOPENV; in comexec()
639 for (i = 0; t->vars[i]; i++) { in comexec()
641 e->loc = l_expand; in comexec()
642 cp = evalstr(t->vars[i], DOASNTILDE | DOSCALAR); in comexec()
643 e->loc = l_assign; in comexec()
652 shf_write(cp, ccp - cp, shl_xtrace); in comexec()
685 switch (tp->type) { in comexec()
687 /* shell built-in */ in comexec()
691 l_assign->flags |= (tp->flag & NEXTLOC_BI); in comexec()
701 if (!(tp->flag & ISSET)) { in comexec()
704 if (!tp->u.fpath) { in comexec()
706 rv = (tp->u2.errnov == ENOENT) ? 127 : 126; in comexec()
709 cstrerror(tp->u2.errnov)); in comexec()
713 if (include(tp->u.fpath, 0, NULL, false) < 0 || in comexec()
715 !(ftp->flag & ISSET)) { in comexec()
718 (ftp->type == CSHELL) && in comexec()
719 (ftp->flag & LOW_BI)) { in comexec()
724 tp->u2.errnov = rv; in comexec()
725 cp = tp->u.fpath; in comexec()
729 "function not defined by", tp->u.fpath); in comexec()
737 * ksh functions set $0 to function name, POSIX in comexec()
741 if (tp->flag & FKSH) in comexec()
745 e->loc->argv = ap; in comexec()
748 e->loc->argc = i - 1; in comexec()
750 * ksh-style functions handle getopts sanely, in comexec()
753 if (tp->flag & FKSH) { in comexec()
754 e->loc->flags |= BF_DOGETOPTS; in comexec()
755 e->loc->getopts_state = user_opt; in comexec()
762 ((tp->flag & TRACE) ? 1 : 0), false); in comexec()
763 old_inuse = tp->flag & FINUSE; in comexec()
764 tp->flag |= FINUSE; in comexec()
766 e->type = E_FUNC; in comexec()
767 if (!(i = kshsetjmp(e->jbuf))) { in comexec()
768 execute(tp->val.t, flags & XERROK, NULL); in comexec()
775 if (tp->flag & FKSH) { in comexec()
782 tp->flag = (tp->flag & ~FINUSE) | old_inuse; in comexec()
788 if ((tp->flag & (FDELETE|FINUSE)) == FDELETE) { in comexec()
789 if (tp->flag & ALLOC) { in comexec()
790 tp->flag &= ~ALLOC; in comexec()
791 tfree(tp->val.t, tp->areap); in comexec()
793 tp->flag = 0; in comexec()
819 if (!(tp->flag&ISSET)) { in comexec()
820 if (tp->u2.errnov == ENOENT) { in comexec()
827 cstrerror(tp->u2.errnov)); in comexec()
832 /* set $_ to program's full path */ in comexec()
835 tp->val.s, KSH_RETURN_ERROR); in comexec()
837 /* to fork, we set up a TEXEC node and call execute */ in comexec()
841 texec.str = tp->val.s; in comexec()
859 rv = exchild(&texec, flags, xerrok, -1); in comexec()
886 *tp->args-- = tp->str; in scriptexec()
889 if ((fd = binopen2(tp->str, O_RDONLY | O_MAYEXEC)) >= 0) { in scriptexec()
900 n = read(fd, buf, sizeof(buf) - 1); in scriptexec()
908 /* skip UTF-8 Byte Order Mark, if present */ in scriptexec()
952 *tp->args-- = (char *)cp; in scriptexec()
959 * might be no /usr/bin/env); for user convenience, if in scriptexec()
974 errorf("%s: not executable: %d-bit ELF file", tp->str, in scriptexec()
989 errorf("%s: not executable: magic %04X", tp->str, m); in scriptexec()
992 cp = _getext(tp->str); in scriptexec()
996 *tp->args-- = "/c"; in scriptexec()
998 for (cp = tp->str; *cp; cp++) { in scriptexec()
1008 args.ro = tp->args; in scriptexec()
1015 errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno)); in scriptexec()
1018 /* actual 'builtin' built-in utility call is handled in comexec() */
1032 * Search function tables for a function. If create set, a table entry
1041 for (l = e->loc; l; l = l->next) { in findfunc()
1042 tp = ktsearch(&l->funs, name, h); in findfunc()
1045 if (!l->next && create) { in findfunc()
1046 tp = ktenter(&l->funs, name, h); in findfunc()
1047 tp->flag = DEFINED; in findfunc()
1048 tp->type = CFUNC; in findfunc()
1049 tp->val.t = NULL; in findfunc()
1072 if (tp->flag & ISSET) in define()
1078 if (tp->flag & FINUSE) { in define()
1079 tp->name[0] = '\0'; in define()
1081 tp->flag &= ~DEFINED; in define()
1082 tp->flag |= FDELETE; in define()
1087 if (tp->flag & ALLOC) { in define()
1088 tp->flag &= ~(ISSET|ALLOC|FKSH); in define()
1089 tfree(tp->val.t, tp->areap); in define()
1098 tp->val.t = tcopy(t->left, tp->areap); in define()
1099 tp->flag |= (ISSET|ALLOC); in define()
1100 if (t->u.ksh_func) in define()
1101 tp->flag |= FKSH; in define()
1115 /* see if any flags should be set for this builtin */ in builtin()
1127 /* external utility overrides built-in utility, always */ in builtin()
1131 /* external utility overrides built-in utility, with flags */ in builtin()
1134 case '-': in builtin()
1143 /* is set or shift */ in builtin()
1155 tp->flag = flag; in builtin()
1156 tp->type = CSHELL; in builtin()
1157 tp->val.f = func; in builtin()
1165 * either function, hashed command, or built-in (in that order)
1171 // fix crash for 'exec -a0' in findcom()
1196 if ((flags & FC_SPECBI) && tbi && (tbi->flag & SPEC_BI)) in findcom()
1200 if (tp && !(tp->flag & ISSET)) { in findcom()
1202 tp->u.fpath = NULL; in findcom()
1203 tp->u2.errnov = ENOENT; in findcom()
1205 tp->u.fpath = search_path(name, fpath, R_OK, in findcom()
1206 &tp->u2.errnov); in findcom()
1213 if (tp && (tp->flag & ISSET) && in findcom()
1214 ksh_access(tp->val.s, X_OK) != 0) { in findcom()
1215 if (tp->flag & ALLOC) { in findcom()
1216 tp->flag &= ~ALLOC; in findcom()
1217 afree(tp->val.s, APERM); in findcom()
1219 tp->flag &= ~ISSET; in findcom()
1224 if ((!tp || (tp->type == CTALIAS && !(tp->flag & ISSET))) && in findcom()
1229 tp->type = CTALIAS; in findcom()
1232 tp->type = CEXEC; in findcom()
1235 tp->flag = DEFINED; in findcom()
1239 X_OK, &tp->u2.errnov); in findcom()
1241 strdupx(tp->val.s, npath.ro, APERM); in findcom()
1244 tp->flag |= ISSET|ALLOC; in findcom()
1248 &tp->u2.errnov)) != NULL) { in findcom()
1252 * even if the command hasn't been set up as an in findcom()
1253 * autoloaded function (ie, no typeset -uf). in findcom()
1256 tp->type = CFUNC; in findcom()
1258 tp->flag = DEFINED; in findcom()
1259 tp->u.fpath = npath.ro; in findcom()
1276 if ((tp->flag&ISSET) && (all || !mksh_abspath(tp->val.s))) { in flushcom()
1277 if (tp->flag&ALLOC) { in flushcom()
1278 tp->flag &= ~(ALLOC|ISSET); in flushcom()
1279 afree(tp->val.s, APERM); in flushcom()
1281 tp->flag &= ~ISSET; in flushcom()
1327 /* set if candidate found, but not suitable */ in search_path()
1359 XcheckN(xs, xp, p - sp); in search_path()
1360 memcpy(xp, sp, p - sp); in search_path()
1361 xp += p - sp; in search_path()
1362 if (mksh_cdirsep(xp[-1])) in search_path()
1363 xp--; in search_path()
1373 /* accumulate non-ENOENT errors only */ in search_path()
1394 builtin_spec = tobool(!resetspec && (tp->flag & SPEC_BI)); in call_builtin()
1398 rv = (*tp->val.f)(wp); in call_builtin()
1407 * set up redirection, saving old fds in e->savefd
1412 int u = -1; in iosetup()
1413 char *cp = iop->ioname; in iosetup()
1414 int iotype = iop->ioflag & IOTYPE; in iosetup()
1444 if (Flag(FNOCLOBBER) && !(iop->ioflag & IOCLOB)) { in iosetup()
1445 /* >file under set -C */ in iosetup()
1462 /* >|file or set +C */ in iosetup()
1473 /* herein() returns -2 if error has been printed */ in iosetup()
1487 X_OK | ((iop->ioflag & IORDUP) ? R_OK : W_OK), in iosetup()
1494 return (-1); in iosetup()
1496 if (u == (int)iop->unit) { in iosetup()
1498 iop->ioflag |= IODUPSELF; in iosetup()
1508 return (-1); in iosetup()
1516 u = -1; in iosetup()
1523 if (u == -1) { in iosetup()
1533 return (-1); in iosetup()
1536 if (e->savefd[iop->unit] == 0) { in iosetup()
1538 if (u == (int)iop->unit) in iosetup()
1539 e->savefd[iop->unit] = -1; in iosetup()
1542 * c_exec() assumes e->savefd[fd] set for any in iosetup()
1543 * redirections. Ask savefd() not to close iop->unit; in iosetup()
1544 * this allows error messages to be seen if iop->unit in iosetup()
1548 e->savefd[iop->unit] = savefd(iop->unit); in iosetup()
1552 close(iop->unit); in iosetup()
1553 else if (u != (int)iop->unit) { in iosetup()
1554 if (ksh_dup2(u, iop->unit, true) < 0) { in iosetup()
1565 return (-1); in iosetup()
1570 * Touching any co-process fd in an empty exec in iosetup()
1573 else if (tp && tp->type == CSHELL && tp->val.f == c_exec) { in iosetup()
1574 if (iop->ioflag & IORDUP) in iosetup()
1596 const char * volatile ccp = iop->heredoc; in hereinval()
1601 if (kshsetjmp(e->jbuf)) { in hereinval()
1605 return (-2); in hereinval()
1607 if (iop->ioflag & IOHERESTR) { in hereinval()
1608 ccp = evalstr(iop->delim, DOHERESTR | DOSCALAR); in hereinval()
1612 s->start = s->str = ccp; in hereinval()
1632 int fd = -1; in herein()
1638 i = (iop->ioflag & IOEVAL) ? (ONEWORD | HEREDOC) : 0; in herein()
1648 h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps); in herein()
1649 if (!(shf = h->shf) || (fd = binopen3(h->tffn, O_RDONLY, 0)) < 0) { in herein()
1652 !shf ? Tcreate : Topen, h->tffn, cstrerror(i)); in herein()
1656 return (-2); in herein()
1659 if (hereinval(iop, i, NULL, shf) == -2) { in herein()
1662 return (-2); in herein()
1665 if (shf_close(shf) == -1) { in herein()
1669 Twrite, h->tffn, cstrerror(i)); in herein()
1671 return (-2); in herein()
1678 * ksh special - the select command processing section
1679 * print the args in column form - assuming that we can
1693 /*- in do_selectargs()
1695 * - this is the first time around the select loop in do_selectargs()
1696 * - the user enters a blank line in do_selectargs()
1697 * - the REPLY parameter is empty in do_selectargs()
1707 ap[i - 1] : null); in do_selectargs()
1725 smi->num_width, i + 1, smi->args[i]); in select_fmt_entry()
1742 * means select can't be used recursively so we re-calculate in pr_menu()
1806 * it is. Returns 0 if it is not, non-zero if it is (in the case of
1816 if (!*te->pos.wp) in dbteste_isa()
1820 for (p = *te->pos.wp; *p == CHAR; p += 2) in dbteste_isa()
1830 p = *te->pos.wp; in dbteste_isa()
1832 (size_t)(q - buf) < sizeof(buf) - 1) in dbteste_isa()
1840 ret = (uqword && !strcmp(*te->pos.wp, in dbteste_isa()
1845 te->pos.wp++; in dbteste_isa()
1853 const char *s = *te->pos.wp; in dbteste_getopnd()
1859 te->pos.wp++; in dbteste_getopnd()
1876 te->flags |= TEF_ERROR; in dbteste_error()