bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tests: avoid problematic $(< file) shell construct


From: Bernhard Voelker
Subject: Re: [PATCH] tests: avoid problematic $(< file) shell construct
Date: Sun, 15 Dec 2013 20:59:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

[moving this topic to bug-gnulib, cc'ing coreutils]

On 12/12/2013 05:33 PM, Pádraig Brady wrote:
> On 12/07/2013 07:41 PM, Pádraig Brady wrote:
>> On 12/07/2013 07:11 PM, Pádraig Brady wrote:
>>> On 12/07/2013 05:39 PM, Bernhard Voelker wrote:
>>>> I'm afraid I'll be tempted to use the $(<file) construct next time
>>>> again.  Do you this it's worth adding a new syntax-check?
>>>
>>> Probably. POSIX says:
>>>
>>> "With the $( command) form, all characters following the open parenthesis
>>> to the matching closing parenthesis constitute the command. Any valid shell
>>> script can be used for command, except a script consisting solely of 
>>> redirections
>>> which produces unspecified results."
>>
>> BTW this would probably be a test non specific to coreutils,
>> so would be based on something like sc_prohibit_reversed_compare_failure in
>> gnulib#s top/maint.mk.
>>
>> So I'll apply without this syntax check for now.
> 
> I see the shell on freebsd silently converts "$(< file)" to ""
> So more reason for a gnulib syntax check

Here it is.

Have a ncie day,
Berny

>From 2caec00693e78b473555a413440f0296f99dd4e0 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Sun, 15 Dec 2013 20:53:55 +0100
Subject: [PATCH] maint.mk: add rule to detect problematic $(< file) shell
 construct

* top/maint.mk (sc_prohibit_redirect_only_command_substitution): Add
new rule.
---
 ChangeLog    | 6 ++++++
 top/maint.mk | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ea8b1ab..32b1199 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-15  Bernhard Voelker  <address@hidden>
+
+       maint.mk: add rule to detect problematic $(< file) shell construct
+       * top/maint.mk (sc_prohibit_redirect_only_command_substitution): Add
+       new rule.
+
 2013-12-12  Alexander V. Lukyanov  <address@hidden>

        md5, sha1, sha256, sha512: fix (trivial) compile error in c++ mode.
diff --git a/top/maint.mk b/top/maint.mk
index 9c02ed4..c9d3691 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1017,6 +1017,15 @@ sc_prohibit_test_double_equal:
        halt='use "test x = x", not "test x =''= x"'                    \
          $(_sc_search_regexp)

+# Avoid problematic redirect-only statements in $(...) shell construct.
+# Although the "man bash" states that this is faster, it does not seem
+# to be portable.  Issues have been seen on dash v0.5.6 and on the shell
+# on FreeBSD.
+sc_prohibit_redirect_only_command_substitution:
+       @prohibit='\$$\(<'              \
+       halt='avoid redirect-only statements, use "$$(cat ...)" instead' \
+         $(_sc_search_regexp)
+
 # Each program that uses proper_name_utf8 must link with one of the
 # ICONV libraries.  Otherwise, some ICONV library must appear in LDADD.
 # The perl -0777 invocation below extracts the possibly-multi-line
-- 
1.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]