bug-bash
[Top][All Lists]
Advanced

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

Short list of issues with various expansions and IFS


From: Dan Douglas
Subject: Short list of issues with various expansions and IFS
Date: Wed, 09 Jan 2013 13:46:28 -0600
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

I'll lump a few issues together here...

 1. Backslash escape adjacent to "$@" expansion separates words.

    $ set -- abc def ghi; printf '<%s> ' "123 $@ 456"; echo
    <123 abc> <def> <ghi 456>
    $ set -- abc def ghi; printf '<%s> ' "123 $@\ 456"; echo
    <123 abc> <def> <ghi\> <456>

Other shells don't do this (though it might even be useful if the backslash
were removed from the result). Depends on the previous fix for
4.2-p36

 2. IFS side-effects don't take effect during expansion.

It isn't clear to me which of these are correct. Bash's interpretation is
unique.

        for sh in bb {{d,b}a,po,{m,}k,z}sh; do
                printf '%-5s ' "${sh}:"
                "$sh" /dev/fd/0
        done <<\EOF
        ${ZSH_VERSION+:} false && emulate sh
        set -f -- a b c
        unset -v IFS
        printf '<%s> ' ${*}${IFS=}${*}${IFS:=-}"${*}"
        echo
        EOF

bb  : <a b cabc> <a-b-c>
dash: <a b cabc> <a-b-c>
bash: <a> <b> <ca> <b> <c-a b c>
posh: <a> <b> <ca b c> <a-b-c>
mksh: <a> <b> <ca b c> <a-b-c>
ksh : <a> <b> <ca> <b> <c> <a b c>
zsh : <a> <b> <ca> <b> <c> <a-b-c>

 3. Another IFS oddity via "command"

IFS can be given "two values at once" through the environment of a
redirection.

 $ ( set -- 1 2 3; IFS=foo; IFS=- command cat <<<"${IFS} ${*}" )
foo 1-2-3
 $ ( set -- 1 2 3; IFS=foo; IFS=- cat <<<"${IFS} ${*}" )
foo 1f2f3

 4. Command substitution in redirection evaluated twice on error.

Reproduce by:

    $ { <$(echo $RANDOM >&3); } 3>&2 2>/dev/null
    25449
    8520

There is a 1-liner patch to redir.c for this which might help demonstrate
(thanks to Eduardo A. Bustamante López <dualbus@gmail.com>). Skipping this
branch when expandable_redirection_filename is false bypasses a huge chunk
that I haven't looked at closely.

diff --git a/redir.c b/redir.c
index 921be8c..f248fd7 100644
--- a/redir.c
+++ b/redir.c
@@ -153,7 +153,7 @@ redirection_error (temp, error)
         }
     }
 #endif
-  else if (expandable_redirection_filename (temp))
+  else if (0)
     {
 expandable_filename:
       if (posixly_correct && interactive_shell == 0)

--
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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