diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2013-07-01 17:25:28 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2013-07-01 17:25:28 +0000 |
commit | 99675b939f7c60356a1229b5a5d13c9468bcb983 (patch) | |
tree | 605fa27bf67a549b0667cb46859f1622b242c412 /bin | |
parent | 9df8345f2e76043e081fe0af80f50d16bc7787d2 (diff) |
Make $(< /nonexistent) have the same behaviour as $(cat /nonexistent)
wrt. errors (do not unwind and do not treat this as fatal if set -e is
used). This matches what bash does. Tweak regress tests while here.
ok millert@, jasper@ agrees
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ksh/eval.c | 14 | ||||
-rw-r--r-- | bin/ksh/tests/obsd-regress.t | 12 | ||||
-rw-r--r-- | bin/ksh/tests/regress.t | 5 |
3 files changed, 24 insertions, 7 deletions
diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index 28f6e79fe19..60aec522fd8 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.38 2013/06/19 12:19:02 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.39 2013/07/01 17:25:27 jca Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -505,7 +505,9 @@ expand(char *cp, /* input word */ break; case XCOM: - if (newlines) { /* Spit out saved nl's */ + if (x.u.shf == NULL) /* $(< ...) failed, fake EOF */ + c = EOF; + else if (newlines) { /* Spit out saved nl's */ c = '\n'; --newlines; } else { @@ -520,9 +522,12 @@ expand(char *cp, /* input word */ } if (c == EOF) { newlines = 0; - shf_close(x.u.shf); + if (x.u.shf != NULL) + shf_close(x.u.shf); if (x.split) subst_exstat = waitlast(); + else + subst_exstat = (x.u.shf == NULL); type = XBASE; if (f&DOBLANK) doblank--; @@ -860,7 +865,8 @@ comsub(Expand *xp, char *cp) shf = shf_open(name = evalstr(io->name, DOTILDE), O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC); if (shf == NULL) - errorf("%s: cannot open $() input", name); + warningf(!Flag(FTALKING), + "%s: cannot open $(<) input", name); xp->split = 0; /* no waitlast() */ } else { int errexit, ofd1, pv[2]; diff --git a/bin/ksh/tests/obsd-regress.t b/bin/ksh/tests/obsd-regress.t index 9338a0f4564..e545bcef93e 100644 --- a/bin/ksh/tests/obsd-regress.t +++ b/bin/ksh/tests/obsd-regress.t @@ -1,4 +1,4 @@ -# $OpenBSD: obsd-regress.t,v 1.4 2013/06/19 14:04:42 millert Exp $ +# $OpenBSD: obsd-regress.t,v 1.5 2013/07/01 17:25:27 jca Exp $ # # ksh regression tests from OpenBSD @@ -256,6 +256,16 @@ expected-stdout: --- +name: input-comsub +description: + A command substitution using input redirection should exit with + failure if the input file does not exist. +stdin: + var=$(< non-existent) +expected-exit: e != 0 +expected-stderr-pattern: /non-existent/ + +--- name: empty-for-list description: A for list which expands to zero items should not execute the body. diff --git a/bin/ksh/tests/regress.t b/bin/ksh/tests/regress.t index 264d415e0fe..e77df1a7432 100644 --- a/bin/ksh/tests/regress.t +++ b/bin/ksh/tests/regress.t @@ -1,4 +1,4 @@ -# $OpenBSD: regress.t,v 1.14 2013/06/19 12:19:03 millert Exp $ +# $OpenBSD: regress.t,v 1.15 2013/07/01 17:25:27 jca Exp $ # # The first 39 of these tests are from the old Bugs script. @@ -605,9 +605,10 @@ description: set -e: errors in command substitutions aren't ignored arguments: !-e! stdin: - echo `false; echo hi` + echo `false; echo hi` $(< this-file-does-not-exist) expected-stdout: hi +expected-stderr-pattern: /this-file-does-not-exist/ --- name: regression-40 |