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 DFFD4C433EF for ; Fri, 31 Dec 2021 16:16:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6A5C83781; Fri, 31 Dec 2021 17:15:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (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="p3s47eoP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EA07D8340A; Fri, 31 Dec 2021 17:15:04 +0100 (CET) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 2ECED83615 for ; Fri, 31 Dec 2021 17:14:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (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-x42e.google.com with SMTP id w20so47696430wra.9 for ; Fri, 31 Dec 2021 08:14:15 -0800 (PST) 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=0108wf8tsczJtQ5ddUBaikwya2FlEsuZM19mhCoPadM=; b=p3s47eoPo5RRr4xSeuROxJKVnja5L3soXuKczXkWPfbJTPjhK2SQGuvVBz8OIzpX2P V4eQyQaEYIcvYkxwCPvxvZJbsMh32lr2bIdK7xuk1HMq7m7zdFagpldpvTFlcb7xawET 8KApShtun+Dp77Q3r7E71s2uvgHiv3GlcLfNs= 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=0108wf8tsczJtQ5ddUBaikwya2FlEsuZM19mhCoPadM=; b=JqUFEcHQ2FoeXp0ykLOI5klGJQ+LXQIy3Wm0jctTwN7z3rOuMDbE+lXpeKwfK9I9+E US62thCP7nzi1I4fl6n+2b2sEbHoJuZraUp8s0R27B0Y8VUwTE85eTsCA2/qlgv9TJZS UDjk/qcNYDPzk0MVAlKqRz7raaO6UbUjfXxS+JDBZzDr8SrlAwKVk0GFjvaT+RsMfQma N9OihUi6ljDokr7UYeEPm8zF/+4W3jB7Wnoh2MSFvNcEhIAPMz6+SxtQEIkdwk40AmTU 4ngBHXmGEybvEfsqoO0CBqImZsXbSeFWCgdJqsx9YlAgZBeFTGyIRKCGu/BXczvxuNyc bhJA== X-Gm-Message-State: AOAM531XVwlp1LK17g5Tx3bBx2nXAn3CeikPzR4G534Must9dEwVToAT ONAZQKsDkGUJQ/N8VvZo+pVQJ0EKGm110g== X-Google-Smtp-Source: ABdhPJyMSkcY8uqd6mKSyxjrBQlqcskwGRyZy68NuKkoy8666yhaYrvDyROoS3rHkbZECz3Sg2G2nQ== X-Received: by 2002:adf:f8cb:: with SMTP id f11mr29456145wrq.700.1640967254755; Fri, 31 Dec 2021 08:14:14 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:eef7:8bf8:8ee0:cb1a]) by smtp.gmail.com with ESMTPSA id f6sm31855522wmq.6.2021.12.31.08.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Dec 2021 08:14:14 -0800 (PST) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Francis Laniel Subject: [RFC PATCH v1 17/21] cli: hush_2021: Enable using \< and \> as string compare operators. Date: Fri, 31 Dec 2021 17:13:23 +0100 Message-Id: <20211231161327.24918-18-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211231161327.24918-1-francis.laniel@amarulasolutions.com> References: <20211231161327.24918-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.38 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.2 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 --- common/cli_hush_2021_upstream.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/common/cli_hush_2021_upstream.c b/common/cli_hush_2021_upstream.c index f2619eb49a..d1f76d4df5 100644 --- a/common/cli_hush_2021_upstream.c +++ b/common/cli_hush_2021_upstream.c @@ -6128,7 +6128,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