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 3800DC6FD1D for ; Thu, 30 Mar 2023 19:59:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 80BDF861D0; Thu, 30 Mar 2023 21:55:10 +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="qhj7LjdH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4ED4E86116; Thu, 30 Mar 2023 21:54:15 +0200 (CEST) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 3C1BA86145 for ; Thu, 30 Mar 2023 21:50:08 +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-x435.google.com with SMTP id e18so20230813wra.9 for ; Thu, 30 Mar 2023 12:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1680205807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CrEsEK+VQyzUUFkwp6MoEWPPjw+Y1IwvDWUuQtPlLoQ=; b=qhj7LjdHXgiUnp71zLjBuwkI5Bk/NG1S97NHndZJlppQN+cGM4tIUzx4vZ3h7ZpWim GlWHc3ikAsQBHIewTrzbJhnikt4RBX5N/w0CMTLQVLSzMXKbCv2NEnuGTLHvMug2stm3 /MJhncDx/H+vi58yAbQ/2hlYTMBLsiV2sp4kQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680205807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CrEsEK+VQyzUUFkwp6MoEWPPjw+Y1IwvDWUuQtPlLoQ=; b=mlO5NWmWOgUHhO6iODA24LRw9Nxo44HgAwdbu4arzu9rh+TnxQ2dhsAhcw825815hm IvjzsJAnow3hYB40v0E7akMCYKakjDwSyIqg74JbiPyHCAuPvkXtBNZoDWoB5jHaS5LK d6BdBv92m6iSRFHctJC3awSuvgNGT78A+dwxRmkVC3dEIPHplIsmeZxOePXEuE+N2mKZ jLT4RAdFwhsuIe2/OpgyiIdAMeyg+JS09G9MhcA6cvC7KTLQTnFQ45zZnUjG9dxpCH2n 5CnKuRJC8vbuJFVyhdRUuVWcTIqchGEhOQk7X/UdgiMaAuFpv+CVLUU/IWqZmtcyx7Zq qt5g== X-Gm-Message-State: AAQBX9dJbHGuuuFdFQH1Ww/6MJtTLXtPR4dCB0mlolj9CPdfPagmkg9M z17yHkg+eX5btnw4m3+4esxrZlPCJmaEmm8bZo1t2w== X-Google-Smtp-Source: AKy350YHbEEG3ZEpk5yXxOMsKKMocs3gzvFyOlG3GA+SQjzCAJX1q98TnUiYJPaR95XDbV7P5kUGZA== X-Received: by 2002:a5d:46c4:0:b0:2ce:92af:adbe with SMTP id g4-20020a5d46c4000000b002ce92afadbemr19145397wrs.59.1680205807628; Thu, 30 Mar 2023 12:50:07 -0700 (PDT) Received: from pwmachine.numericable.fr ([78.30.11.60]) by smtp.gmail.com with ESMTPSA id l24-20020a1c7918000000b003e203681b26sm203762wme.29.2023.03.30.12.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:50:07 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , "Albert ARIBAUD (3ADEV)" , Tony Dinh , Sergei Antonov , Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Stefan Roese , John Keeping , Neil Armstrong , Roger Knecht , Robert Marko , Samuel Dionne-Riel , Alexey Romanov , Marek Vasut , Patrice Chotard , Patrick Delaunay , Fabrice Gasnier , Hector Palacios , Rasmus Villemoes , AKASHI Takahiro , Linus Walleij , Rui Miguel Silva , Andrew Scull Subject: [RFC PATCH v7 18/23] cli: hush_2021: Enable using < and > as string compare operators Date: Thu, 30 Mar 2023 20:47:06 +0100 Message-Id: <20230330194716.23623-19-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230330194716.23623-1-francis.laniel@amarulasolutions.com> References: <20230330194716.23623-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.8 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 '\>'). 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 Reviewed-by: Simon Glass --- common/cli_hush_upstream.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c index dbf77ad503..68a9a4bb72 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -6160,7 +6160,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" */ -- 2.34.1