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 D6A7EC7EE23 for ; Thu, 8 Jun 2023 18:39:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B01D386195; Thu, 8 Jun 2023 20:36:11 +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="C8EoVqOd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BEFC686133; Thu, 8 Jun 2023 20:36:07 +0200 (CEST) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 362EF861D6 for ; Thu, 8 Jun 2023 20:35:48 +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-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f738f579ceso7066425e9.3 for ; Thu, 08 Jun 2023 11:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1686249348; x=1688841348; 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=C8EoVqOdGAiL2UTYqg7joYQxK+Ah8owZwf2/oZnczloCHEXPS9Hk9cA5Swfv0c7Sg6 uMEUOuUYovkWhYstg52zrwNlukf/CaFfJ/YGjmULYsCjhMO1BzY7aO53LhKT7mqsrsIx 9Fn2EQACqIMOECZNoIodPXh0Don5v3ViDoUUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686249348; x=1688841348; 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=C2NWNvZz8Utba7Z1uiiYTxTKfWos+hHA+DZLbaMWRgZZ4A1fLSmpCkUhT4eE71ikn7 34FqukKB9OWsNZAaQMSfULK3kNjwa+4t3On334QRJ1jOqmN8rkn/INohVl3iXUHkdhjd IdnUC6uvw7YcJAV7TlqVD0zsIGT9MU04THxKpIo537q8ws5smg5XoptecQvNhOY6kSz+ mSLc8URdsvE+3IhG9Zama21PIqalEZx4q1RNMtA2ryqgncmBAgxLozsYPWz32wIUlge3 x1hCCffJhDxJR8tBd92TsTSS89YRXQgZgedV7xNkWOpFblvqexg4Gm89s2q5zefTXT21 1Y1A== X-Gm-Message-State: AC+VfDyjgVRx6/AkpytuOwpvFL2o1bsSsZH7WO//xt/GA31cZR8JKd7l 8eRBGA19LgIMrPv6E5Zyjy9hOt93oIJfpy8alb83Ew== X-Google-Smtp-Source: ACHHUZ4QnV56vu9lH8YwdLaVZBRR781APsj9Rgb2de+Nnv/gExw7k+npVgLMRQTt6hUtNCxfK82bzA== X-Received: by 2002:a1c:741a:0:b0:3f5:6e6:9d83 with SMTP id p26-20020a1c741a000000b003f506e69d83mr1957675wmc.23.1686249347967; Thu, 08 Jun 2023 11:35:47 -0700 (PDT) Received: from pwmachine.home (120.124.191.92.dynamic.jazztel.es. [92.191.124.120]) by smtp.gmail.com with ESMTPSA id t10-20020a1c770a000000b003f8009be6c0sm408783wmi.3.2023.06.08.11.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 11:35:47 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , Tony Dinh Subject: [RFC PATCH v9 18/23] cli: hush_2021: Enable using < and > as string compare operators Date: Thu, 8 Jun 2023 19:34:33 +0100 Message-Id: <20230608183438.16748-19-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230608183438.16748-1-francis.laniel@amarulasolutions.com> References: <20230608183438.16748-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