REDIRFD_CLOSE = -3,
REDIRFD_SYNTAX_ERR = -2,
- REDIRFD_TO_FILE = -1,
- /* otherwise, rd_fd is redirected to rd_dup */
+ REDIRFD_TO_FILE = -1, /* otherwise, rd_fd if redirected to rd_dup */
HEREDOC_SKIPTABS = 1,
HEREDOC_QUOTED = 2,
ctx->pending_redirect->rd_dup |= HEREDOC_QUOTED;
}
debug_printf_parse("word stored in rd_filename: '%s'\n", word->data);
+ ctx->pending_redirect = NULL;
} else {
/* If this word wasn't an assignment, next ones definitely
* can't be assignments. Even if they look like ones. */
debug_print_strings("word appended to argv", command->argv);
}
- o_reset(word);
- ctx->pending_redirect = NULL;
-
#if ENABLE_HUSH_LOOPS
- /* Force FOR to have just one word (variable name) */
- /* NB: basically, this makes hush see "for v in ..." syntax as if
- * as it is "for v; in ...". FOR and IN become two pipe structs
- * in parse tree. */
if (ctx->ctx_res_w == RES_FOR) {
- if (!is_well_formed_var_name(command->argv[0], '\0')) {
- syntax_error("malformed variable name in for");
+ if (word->o_quoted
+ || !is_well_formed_var_name(command->argv[0], '\0')
+ ) {
+ /* bash says "not a valid identifier" */
+ syntax_error("not a valid identifier in for");
return 1;
}
+ /* Force FOR to have just one word (variable name) */
+ /* NB: basically, this makes hush see "for v in ..."
+ * syntax as if it is "for v; in ...". FOR and IN become
+ * two pipe structs in parse tree. */
done_pipe(ctx, PIPE_SEQ);
}
#endif
done_pipe(ctx, PIPE_SEQ);
}
#endif
+
+ o_reset(word);
+
debug_printf_parse("done_word return 0\n");
return 0;
}
if (argv[1]) {
name = argv[1];
+ /* bash (3.2.33(1)) bug: "read 0abcd" will execute,
+ * and _after_ that_ it will complain */
if (!is_well_formed_var_name(name, '\0')) {
/* Mimic bash message */
bb_error_msg("read: '%s': not a valid identifier", name);
}
}
+//TODO: bash unbackslashes input, splits words and puts them in argv[i]
+
string = xmalloc_reads(STDIN_FILENO, xasprintf("%s=", name), NULL);
return set_local_var(string, 0, 0);
}
--- /dev/null
+# UNFIXED BUG: hush thinks that ; && || & have the same precedence.
+# According to this doc, && || have higher precedence than ; &.
+# See example below.
+# Precedence of ; is not a problem in practice. Precedence of & is.
+#
+#http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
+#
+#2.9.3 Lists
+#
+#An AND-OR list is a sequence of one or more pipelines separated by
+#the operators "&&" and "||" .
+#
+#A list is a sequence of one or more AND-OR lists separated by the operators
+#';' and '&' and optionally terminated by ';', '&', or <newline>.
+#
+#The operators "&&" and "||" shall have equal precedence and shall be
+#evaluated with left associativity. For example, both of the following
+#commands write solely bar to standard output:
+#
+# false && echo foo || echo bar
+# true || echo foo && echo bar
+#
+#A ';' or <newline> terminator shall cause the preceding AND-OR list
+#to be executed sequentially; an '&' shall cause asynchronous execution
+#of the preceding AND-OR list.
+
+echo First && sleep 0.2 && echo Third &
+sleep 0.1
+echo Second
+wait
+echo Done