aboutsummaryrefslogtreecommitdiff
path: root/lib/wordsplit.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/wordsplit.c')
-rw-r--r--lib/wordsplit.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/wordsplit.c b/lib/wordsplit.c
index 9f1b9d5..d1851bf 100644
--- a/lib/wordsplit.c
+++ b/lib/wordsplit.c
@@ -669,10 +669,20 @@ expvar(struct wordsplit *wsp, const char *str, size_t len,
return _wsplt_nomem(wsp);
} else if (wsp->ws_flags & WRDSF_GETVAR)
value = wsp->ws_getvar(str, i);
- else if (wsp->ws_flags & WRDSF_KEEPUNDEF)
+ else if (wsp->ws_flags & WRDSF_UNDEF) {
+ wsp->ws_errno = WRDSE_UNDEF;
+ if (wsp->ws_flags & WRDSF_SHOWERR)
+ wordsplit_perror(wsp);
+ return 1;
+ } else {
+ if (wsp->ws_flags & WRDSF_WARNUNDEF)
+ wsp->ws_error(_("warning: undefined variable `%.*s'"),
+ i, str);
+ if (wsp->ws_flags & WRDSF_KEEPUNDEF)
value = NULL;
else
value = "";
+ }
/* FIXME: handle defstr */
if (value) {
if (flg & _WSNF_QUOTE) {
@@ -1221,8 +1231,7 @@ wordsplit_perror(struct wordsplit *wsp)
break;
case WRDSE_NOSUPP:
- wsp->ws_error(_("command substitution "
- "is not yet supported"));
+ wsp->ws_error(_("command substitution is not yet supported"));
case WRDSE_USAGE:
wsp->ws_error(_("invalid wordsplit usage"));
@@ -1232,6 +1241,10 @@ wordsplit_perror(struct wordsplit *wsp)
wsp->ws_error(_("unbalanced curly brace"));
break;
+ case WRDSE_UNDEF:
+ wsp->ws_error(_("undefined variable"));
+ break;
+
default:
wsp->ws_error(_("unknown error"));
}
@@ -1244,7 +1257,8 @@ const char *_wordsplit_errstr[] = {
N_("variable expansion and command substitution "
"are not yet supported"),
N_("invalid wordsplit usage"),
- N_("unbalanced curly brace")
+ N_("unbalanced curly brace"),
+ N_("undefined variable")
};
int _wordsplit_nerrs = sizeof(_wordsplit_errstr)/sizeof(_wordsplit_errstr[0]);

Return to:

Send suggestions and report system problems to the System administrator.