From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC47BC43334 for ; Thu, 16 Jun 2022 22:35:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C2C8B844B6; Fri, 17 Jun 2022 00:33:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="BZYZbJ/8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AD42084485; Fri, 17 Jun 2022 00:33:44 +0200 (CEST) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3BAE0843D3 for ; Fri, 17 Jun 2022 00:33:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=francis.laniel@amarulasolutions.com Received: by mail-wr1-x433.google.com with SMTP id g4so3533992wrh.11 for ; Thu, 16 Jun 2022 15:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6NapdmHtP+U9plYrKkLVAodXqOaaXGGcKMQQRbyycCc=; b=BZYZbJ/8wf8J2uFNC6B2t3Q335SgCYQDtOzRns+y0MG8KWexnHcYWVA/38dDyADYsh eBeDqQJJ1kuCsB+SjYE4IGEeyMrY997jZHdLF6pYveCccUDPd3DlIBKXYfCFeofiR7FJ cm9tAc93RDKOJUnDGzUJ2WW+oaeAfkLk1ESgI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6NapdmHtP+U9plYrKkLVAodXqOaaXGGcKMQQRbyycCc=; b=eZ6CpQbbHgNr0wibHcUOMxJQxHQbtJvVikM9R0GFtQYLI/vrPgfCE7diJ4r1nNk9TC H2I/JuAfM4W5JbR5YuBQqezw/m9IHb6YYWqwO/P+lLpwQlrRwG9Ku1JePKyQZimk9Usj NwEYExyC4NvihySOi3mYDoDZO65Fqd3q26png2J5SsUXtjCVu8FEBttopJK9ICOce7vh YLd1ZCrx2WIS4+WgYc6mVrItJ36vTLX3953jIldsJX867mWAp+vx1ZEgvf4IjAhnXi3y 2MC2XvSRQWays9IElhK2RWmVE5sNGFEV81nDdazunjciQSTDT3CMlXTf5spNsdVcAM1d q4ZQ== X-Gm-Message-State: AJIora+G/YMkW/XuZqn5p7IzHv8Bf08cqP9FxLYqW7LBqLSlWCBQVw+j IwVj0675R6OdcTKaFe+lzWZJtsy6y93s1A== X-Google-Smtp-Source: AGRyM1sKmLNp5Mcev/eXZcXdbgd0DIxBDI8eGgfodbdZPnnWstzepNhANH5OLhWnT5IsjKi1Vg5v4w== X-Received: by 2002:a5d:4405:0:b0:219:e73e:8312 with SMTP id z5-20020a5d4405000000b00219e73e8312mr6478977wrq.499.1655418795997; Thu, 16 Jun 2022 15:33:15 -0700 (PDT) Received: from pwmachine.home (17.pool80-103-97.dynamic.orange.es. [80.103.97.17]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm7912044wmq.20.2022.06.16.15.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 15:33:15 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Tom Rini , Francis Laniel Subject: [RFC PATCH v4 19/28] cli: hush_2021: Enable using \< and \> as string compare operators Date: Fri, 17 Jun 2022 00:31:49 +0200 Message-Id: <20220616223158.9225-20-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> References: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 '\>'), so we stick here to this behavior. Also, 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. Signed-off-by: Francis Laniel Reviewed-by: Simon Glass --- common/cli_hush_upstream.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c index a768fd6197..6ef6bb6bf4 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -6161,7 +6161,33 @@ 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, using test foo < bar will show the + * following error: + * hush: can't open 'bar': No such file or directory + * Indeed, in this context, '>' and '<' are used as redirection + * operators, to use them as sorting operators, one should use: + * [[ foo < bar ]] + * Or: + * test foo \< bar + * + * For the moment, we will not implement [[ ]], so we will need + * the user to escape these operators to use them as string + * comparaison operators. + * 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 '<': + printf("Redirection operator ('%c') is not supported!\nPlease escape it ('\\%c') to use it as string comparaison operator.\n", (char) ch, (char) ch); + goto parse_error_exitcode1; +#endif /* __U_BOOT__ */ case '#': if (ctx.word.length == 0 && !ctx.word.has_quoted_part) { /* skip "#comment" */ -- 2.25.1