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 94E0CC433EF for ; Sun, 6 Feb 2022 18:40:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9BA5383BE2; Sun, 6 Feb 2022 19:38:44 +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="bacOaQ9H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7DD9683BD7; Sun, 6 Feb 2022 19:38:43 +0100 (CET) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (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 9293283C12 for ; Sun, 6 Feb 2022 19:37:53 +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-x42f.google.com with SMTP id e3so7192452wra.0 for ; Sun, 06 Feb 2022 10:37:53 -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=+CGOZEOXGqfEc657oVley/DZ2fgh+cUxmUVsGXFXugo=; b=bacOaQ9HadKLr1QFRar+gqXOCWvrbhzazg45W+AGy692By/lfWgSPJ0v9rIUaNxHQI x+4zTv5dJF1Rt62iViqeJTDjAR6wxOtsAGV8LIxaldqI5DHmR/AUb8+z4Z0BxJAWJcgi T4t1GYwJmJ+ydtG06SMpFcEeTSY7jPVEJtGKA= 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=+CGOZEOXGqfEc657oVley/DZ2fgh+cUxmUVsGXFXugo=; b=MDTVRrtus4VFFvNdIYKIgRSobThmTD/PW8XWur1dxPmqnv0XPQfbOnPcL7syT27C3g sm3KWlR3XknjfMdqKoOGFu9CwHoof5wta1ciFJR9ikojaXLP/CNSwGHAEKbahJj8KJXI hq0Fl4k4IClDo5K3OoNXDrsIbkUOIZw6Zxy/J8R25Dt9uYkRttNl5QarQ9lW3wNm+6xw rdokuuqOlJHOREhQ8RSC50UvzdJLtVnnQ/4epfdWEKVY7cISt2b1zh92zRAGw2Jz+q5p 6jLSg/njGFsF4WuopHFBRUhkL3f9pWj+IhpXJyWR0xeIgTNbIVJTfUfsdlSitGtrEX6X ymOQ== X-Gm-Message-State: AOAM531xpj+CzL02AW2shZgXOL1wO+8aOYvx/FO4/F7G9kKtsGc1jICC JhW8x2TUIKS7AcP1QmrM7xYbSDVyLkgwgA== X-Google-Smtp-Source: ABdhPJy+2/wdtANzLHnRd4p0KPJpzMc4OWwclnFKybSCbaEaBrVSuJJZAWBdnB7RmbUeqlZd9CqIkw== X-Received: by 2002:adf:e350:: with SMTP id n16mr6788303wrj.180.1644172673180; Sun, 06 Feb 2022 10:37:53 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:e5b3:218b:cb92:2549]) by smtp.gmail.com with ESMTPSA id ay29sm7095011wmb.38.2022.02.06.10.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 10:37:52 -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 v2 17/21] cli: hush_2021: Enable using \< and \> as string compare operators Date: Sun, 6 Feb 2022 19:37:13 +0100 Message-Id: <20220206183717.57446-18-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220206183717.57446-1-francis.laniel@amarulasolutions.com> References: <20220206183717.57446-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 f2619eb49a..d1f76d4df5 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_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