mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 15:14:43 +00:00
cli: hush_modern: Enable using < and > as string compare operators
In Busybox hush, '<' and '>' are used as redirection operators. For example, cat foo > bar will write content of file foo inside file bar. In U-Boot, we do not have file system, so we can hardly redirect command output inside a file. But, in actual U-Boot hush, these operators ('<' and '>') are used as string compare operators. For example, test aaa < bbb returns 0 as aaa is before bbb in the dictionary. Busybox hush also permits this, but operators need to be escaped ('\<' and '\>'). Indeed, if escaping is needed it permits the developer to think about its code, as in a lot of case, we want to compare integers (using '-lt' or '-gt') rather than strings. As testing in U-Boot is handled by the test command, we will stick with the original behaviour and not adapt to Busybox one. Nonetheless, if one day we decide to implement test with '[[ ]]', we will then stick to upstream Busybox behavior. Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
410e78df06
commit
d8b256308d
1 changed files with 22 additions and 1 deletions
|
@ -6159,7 +6159,28 @@ static struct pipe *parse_stream(char **pstring,
|
|||
if (parse_redirect(&ctx, redir_fd, redir_style, input))
|
||||
goto parse_error_exitcode1;
|
||||
continue; /* get next char */
|
||||
#endif /* !__U_BOOT__ */
|
||||
#else /* __U_BOOT__ */
|
||||
/*
|
||||
* In U-Boot, '<' and '>' can be used in test command to test if
|
||||
* a string is, alphabetically, before or after another.
|
||||
* In 2021 Busybox hush, we will keep the same behavior and so not treat
|
||||
* them as redirection operator.
|
||||
*
|
||||
* Indeed, in U-Boot, tests are handled by the test command and not by the
|
||||
* shell code.
|
||||
* So, better to give this character as input to test command.
|
||||
*
|
||||
* NOTE In my opinion, when you use '<' or '>' I am almost sure
|
||||
* you wanted to use "-gt" or "-lt" in place, so thinking to
|
||||
* escape these will make you should check your code (sh syntax
|
||||
* at this level is, for me, error prone).
|
||||
*/
|
||||
case '>':
|
||||
fallthrough;
|
||||
case '<':
|
||||
o_addQchr(&ctx.word, ch);
|
||||
continue;
|
||||
#endif /* __U_BOOT__ */
|
||||
case '#':
|
||||
if (ctx.word.length == 0 && !ctx.word.has_quoted_part) {
|
||||
/* skip "#comment" */
|
||||
|
|
Loading…
Reference in a new issue