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 AECBFC77B75 for ; Fri, 12 May 2023 20:09:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C55B8636B; Fri, 12 May 2023 22:07:35 +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="IPLY95SX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F0448633D; Fri, 12 May 2023 22:07:25 +0200 (CEST) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 B692E862FD for ; Fri, 12 May 2023 22:07:17 +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-x32d.google.com with SMTP id 5b1f17b1804b1-3f41d087bd3so51496995e9.3 for ; Fri, 12 May 2023 13:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1683922027; x=1686514027; 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=IPLY95SXXP9N/PreqoPNFedBnQUikbPkYC9REIemTvG76azELvEzlFHR1nfyUDvQZv cpsnUutjRkYK6SAMFgw6R9GfYBS/RB3y7aYuDqtOEVO0C1sgq3UaBZu69cLK248G+DRo cSOrVT0xnh8kFw5Ck0dILVwdyWRHYZelMFF4s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683922027; x=1686514027; 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=jhCPgZtrGzBWDJGBeC/T0UkNB1kvsxOqaG8qcNTADx6VXvLgDK26B/MTVVbMgEJOqt pTaQSFOIbPA6OLUF8WHJnWwNcTlM2bUBuYmbXjwhJKvkfHnfJV9o+yt6mgdw8gYjthkS gl5N/l14Uem1BpOyDsdNeiafErTcj2SAY8ITFvzvUQTbO/KwZC//CH0HWKbC8wT1jC9D u4UaA8W/fFiitGuOMV1J4JDZoM0xoDo+qZgpn7Po3bW50wQnWRtZNNuPsrjqHXg6RWGD TiGceArnjLcLP5zRlxkftc2MGUaliWzSijXLCYaaH0Vhe1qp9eKORB+HuHXJL/0KN+l1 kjag== X-Gm-Message-State: AC+VfDw9zKfeeQN4RpMwheMs5P6kWCkg3muF9Mgwr7XO+GNKjf40dxrZ HBynylSvMlTVvBlMl43qUQRzyKFbXYYXR/NUUBA= X-Google-Smtp-Source: ACHHUZ6HRHRklRSUEDGLSn5/iw39+Hu3Hoh/QlG1dsKALd0AFebsJ9s18q0EFPG+Us3/04BbrfOlSg== X-Received: by 2002:a7b:cb8a:0:b0:3f4:2174:b29c with SMTP id m10-20020a7bcb8a000000b003f42174b29cmr14645402wmi.20.1683922027138; Fri, 12 May 2023 13:07:07 -0700 (PDT) Received: from pwmachine.numericable.fr ([213.94.16.214]) by smtp.gmail.com with ESMTPSA id n6-20020a7bcbc6000000b003f33f8f0a05sm29565859wmi.9.2023.05.12.13.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:07:04 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel Subject: [RFC PATCH v8 18/23] cli: hush_2021: Enable using < and > as string compare operators Date: Fri, 12 May 2023 21:03:26 +0100 Message-Id: <20230512200331.51457-19-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> References: <20230512200331.51457-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