bug-bash
[Top][All Lists]
Advanced

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

Re: IFS set to backslash


From: Thorsten Glaser
Subject: Re: IFS set to backslash
Date: Wed, 8 Apr 2015 16:03:38 +0200 (CEST)
User-agent: Alpine 2.11 (DEB 23 2013-08-11)

Hi!

Thanks for these analysēs! Please steer stuff like this to
the mksh list in the future as well (and/or prod me on IRC).
TIA! (Sorry for the late reply, I just discovered this in my
postponed-msgs eMail folder and finished it to be sendable.)


On Wed, 7 Jan 2015, Eduardo A. Bustamante López wrote:

> - ksh93 and mksh behave identically, except for #5 and #11 (I think
>   this is an mksh bug).

> # -   code [ # input ]                               bash  ksh93  mksh  zsh   
> bbsh  bsh   dash
> # 5   IFS=\\ read f g; printf %s\\n "$f" # <\^J>     <>    <      <>    <     
> <>    <>    <>
> # 11  IFS=\\ read f; printf %s\\n "$f" # <\^J>       <>    <      <>    <>    
> <>    <>    <>

From POSIX, this is a ksh93 bug, in which mksh behaves correctly:

|    By default, unless the -r option is specified, <backslash> shall
|    act as an escape character. An unescaped <backslash> shall preserve
|    the literal value of the following character, with the exception of
|    a <newline>. If a <newline> follows the <backslash>, the read
|    utility shall interpret this as line continuation. The <backslash>
|    and <newline> shall be removed before splitting the input into
|    fields. All other unescaped <backslash> characters shall be removed
|    after splitting the input into fields.

The thing to do here seems to be, in both cases:

• read reads '<' '\\' '\n' '>'
• read removes the '\\' '\n' sequence from the input string,
  as it’s not called with -r
• the remaining string '<' '>' is sent to field splitting,
  keeping it as-is

Could someone™ please inform dgk of this (if he doesn’t read
this newsgroup)?


>   From POSIX, I think the ksh's are wrong in #9 and #10.

> # -   code [ # input ]                               bash  ksh93  mksh  zsh   
> bbsh  bsh   dash
> # 9   IFS=\\ read f; printf %s\\n "$f" # <\>         <>    <\>    <\>   <>    
> <>    <>    <>
> # 10  IFS=\\ read f; printf %s\\n "$f" # <\\>        <\>   <\\>   <\\>  <\>   
> <\>   <\>   <\>

Hrm. The '\\' is IFS non-whitespace and thus behaves like 'x'…

address@hidden:~ $ IFS=\\ read f; printf %s\\n "$f"
<\>
<\>
address@hidden:~ $ IFS=x read f; printf %s\\n "$f"
<x>
<x>
address@hidden:~ $ IFS=\\ read f; printf %s\\n "$f"
<\\>
<\\>
address@hidden:~ $ IFS=x read f; printf %s\\n "$f"
<xx>
<xx>

… except POSIX additionally says:

|    All other unescaped <backslash> characters shall be removed
|    after splitting the input into fields.

So, I agree the correct output for #9 and #10, respectively, is
probably '<' '>' and '<' '\\' '>', as in GNU bash and others.

> The script I used to generate this is attached.

Thank you!

bye,
//mirabilos
-- 
Yes, I hate users and I want them to suffer.
        -- Marco d'Itri on gmane.linux.debian.devel.general



reply via email to

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