From patchwork Fri Sep 7 08:34:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592273 X-Patchwork-Delegate: herbert@gondor.apana.org.au Delivered-To: konstantin@linuxfoundation.org Received: by 2002:a0c:fb06:0:0:0:0:0 with SMTP id c6-v6csp1459120qvp; Fri, 7 Sep 2018 01:34:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZGOO87c3l4J1LFwB9vNKN9aHl1gpWJ1DiiArYkID9X/8LHd30fCpZCmT6Bne+xK8Cu8iYC X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr6893490pld.48.1536309288230; Fri, 07 Sep 2018 01:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309288; cv=none; d=google.com; s=arc-20160816; b=CPgLfuybLuwO3uJ1JrkSI7k2fAAZM1SaQn8L3wBNiIaQsNI5MUCZNCo7pbxHcmwAri U1BATWX3d84uwxuuvs66wPDLUN72udP8+Kd/0hO1Up+dH2VqsLSyk//94a6aDvWGypVK XH1HXsK8sJYeV8rcPV78TfAcMTvjicJrcqx4ib5eaOSnw6FoEXYPRurKnyfoDAQ6mvpK fSCcRPyOTm7HhjEYXWD0ZrhOgjs48lfE3hfBUbOGAn0OMZJx+mqXaY5xO85TBbIM55+x K1uSoqQH8IgdMtXvh5LB1KSg5A5vJHZ0WYZmRMx4y6OtLf5Iqw6wM40ehNWF/+/5JuSy m5ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=6E1I5bLfI5POVWFKcko0EBXQ1XtUou/mc+xFs+rC+3Y=; b=KgM+0ckZz7Uwie1tLOXc0KenupgBv4dpQqC4INq5rVKJ6xKitWG7RhqEMIVT6Nh9aw bmMXjgnWzeOO4dhbcJexuUZ/DiS0Yl6N2DXWjTtlXRRm74ADqSVNPuwtyiAWc/ljwod7 AoM4md6EiuBM90YDkzEV9pE7RQIphfu/k4rt3UUZ42iwsPn60zmY73eBu1wKQz+MQuYl FBWjhvLlJ85kisPnEK0vmml+XOHRDL3s4GKl86zps+PcHXwckKNz1NC2wfjeeR+YCY/Y axvlUlOZ1ax2TfdGAG6zBuaL9t7ZcyKco4QFZ4NetLMtpF8SMDzYjLkfd3HeWY+un5ek bNOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) smtp.mailfrom=dash-owner@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.co.uk Return-Path: Received: from mail.wl.linuxfoundation.org (mail.wl.linuxfoundation.org. [198.145.29.98]) by mx.google.com with ESMTPS id m18-v6si8013487pgb.136.2018.09.07.01.34.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) client-ip=198.145.29.98; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) smtp.mailfrom=dash-owner@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.co.uk Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F8C2ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C681D2ADE1; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 772102ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69DAE2ADE1; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A5A72ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbeIGNOi (ORCPT ); Fri, 7 Sep 2018 09:14:38 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35240 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIGNOi (ORCPT ); Fri, 7 Sep 2018 09:14:38 -0400 Received: from localhost (2a02-ab04-03b9-5e00-0000-0000-0000-0003.dynamic.v6.chello.sk [IPv6:2a02:ab04:3b9:5e00::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: andrewsh) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5232C27D871; Fri, 7 Sep 2018 09:34:40 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 2/6] printf: Support \e in "echo" and "printf" builtins. Date: Fri, 7 Sep 2018 10:34:10 +0200 Message-Id: <20180907083414.14673-3-andrew.shadura@collabora.co.uk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907083414.14673-1-andrew.shadura@collabora.co.uk> References: <20180907083414.14673-1-andrew.shadura@collabora.co.uk> Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP X-Virus-Scanned: ClamAV using ClamSMTP Status: O Content-Length: 2016 Lines: 57 From: Adam Borowski dash's builtin version of printf doesn't support '\e' (escape), and literaly outputs the 2 characters as-is. As is well known, this sequence is useful, for example, when outputting ANSI escape sequences. While it seems that POSIX does not require that printf support '\e', it is still worth implementing '\e' support, as a way to make the environment more consistent and avoid this small issue when porting scripts from certain other systems or when migrating from bash to dash. Signed-off-by: Adam Borowski [reworded the patch description] Signed-off-by: Andrej Shadura Bug-Debian: http://bugs.debian.org/816295 --- src/bltin/printf.c | 1 + src/dash.1 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/bltin/printf.c b/src/bltin/printf.c index 7785735..9b878da 100644 --- a/src/bltin/printf.c +++ b/src/bltin/printf.c @@ -340,6 +340,7 @@ conv_escape(char *str, int *conv_ch) case '\\': value = '\\'; break; /* backslash */ case 'a': value = '\a'; break; /* alert */ case 'b': value = '\b'; break; /* backspace */ + case 'e': value = '\e'; break; /* escape */ case 'f': value = '\f'; break; /* form-feed */ case 'n': value = '\n'; break; /* newline */ case 'r': value = '\r'; break; /* carriage-return */ diff --git a/src/dash.1 b/src/dash.1 index 32f6ac0..b286f79 100644 --- a/src/dash.1 +++ b/src/dash.1 @@ -1201,6 +1201,8 @@ Subsequent output is suppressed. This is normally used at the end of the last argument to suppress the trailing newline that .Ic echo would otherwise output. +.It Li \ee +Outputs an escape character (ESC). .It Li \ef Output a form feed. .It Li \en @@ -1570,6 +1572,8 @@ The characters and their meanings are as follows: Write a \*[Lt]bell\*[Gt] character. .It Cm \eb Write a \*[Lt]backspace\*[Gt] character. +.It Cm \ee +Write an \*[Lt]escape\*[Gt] (ESC) character. .It Cm \ef Write a \*[Lt]form-feed\*[Gt] character. .It Cm \en