From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4791015817D for ; Fri, 21 Jun 2024 13:14:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C7B69E2A56; Fri, 21 Jun 2024 13:14:19 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id ABD46E2A7D for ; Fri, 21 Jun 2024 13:14:19 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EE1CF33D9AD for ; Fri, 21 Jun 2024 13:14:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 51BB51D57 for ; Fri, 21 Jun 2024 13:14:15 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1718176002.a46a94768d76cd1f52cc7d6743575887fa416407.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: a46a94768d76cd1f52cc7d6743575887fa416407 X-VCS-Branch: master Date: Fri, 21 Jun 2024 13:14:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 7e9ae995-c4ae-46c4-a5a8-bfa1532109d9 X-Archives-Hash: af8555ed8570af2eaf41c8bc571b4e7a commit: a46a94768d76cd1f52cc7d6743575887fa416407 Author: Kerin Millar plushkava net> AuthorDate: Thu Jun 6 00:23:54 2024 +0000 Commit: Sam James gentoo org> CommitDate: Wed Jun 12 07:06:42 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=a46a9476 Have quote_args() respect POSIXLY_CORRECT for Issue 7 conformance Also, markedly improve the comment that documents the function. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/functions.sh b/functions.sh index f440dab..79cd06a 100644 --- a/functions.sh +++ b/functions.sh @@ -540,19 +540,29 @@ parallel_run() } # -# Prints the positional parameters in a manner that approximates the behaviour -# of the ${*@Q} expansion in bash. The output shall be POSIX sh compatible as of -# Issue 8. This should probably be made to exist as a standalone awk script. +# Prints the positional parameters in a format that may be reused as shell +# input. For each considered, it shall be determined whether its value contains +# any non-printable characters in lieu of the US-ASCII character set. If no such +# characters are found, the value shall have each instance of be +# replaced by before being +# enclosed by a pair of characters. Otherwise, non-printable +# characters shall be replaced by octal escape sequences, by +# and by , prior to +# the value being given a prefix of and a suffix of +# , per Issue 8. Finally, the resulting values shall be printed as +# separated. The latter quoting strategy can be suppressed by setting +# the POSIXLY_CORRECT variable as non-empty in the environment. # quote_args() { awk -v q=\' -f - -- "$@" <<-'EOF' BEGIN { + strictly_posix = length(ENVIRON["POSIXLY_CORRECT"]) argc = ARGC ARGC = 1 for (arg_idx = 1; arg_idx < argc; arg_idx++) { arg = ARGV[arg_idx] - if (arg !~ /[\001-\037\177]/) { + if (strictly_posix || arg !~ /[\001-\037\177]/) { gsub(q, q "\\" q q, arg) word = q arg q } else {