[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
IFS set to backslash
From: |
Eduardo A . Bustamante López |
Subject: |
IFS set to backslash |
Date: |
Wed, 7 Jan 2015 23:07:22 -0800 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
I was playing with the following scenario:
IFS set to backslash,
using read (with and without -r),
triggering field splitting by passing multiple names to read,
triggering field splitting by expanding an unquoted parameter.
And, I found the following results:
(note: the ones with a # <something>, that means that the 'read' was fed that
something, via: "$sh" -c 'code that reads' <<< "something")
(note: bbsh is busybox ash, and bsh is heirloom sh)
# - code [ # input ] bash ksh93 mksh zsh
bbsh bsh dash
# 1 IFS=\\ a=\<\\\>; printf %s\\n $a <^J> <^J> <^J> <^J>
<^J> <\> <^J>
# 2 IFS=: b=\<:\>; printf %s\\n $b <^J> <^J> <^J> <^J>
<^J> <^J> <^J>
# 3 IFS=\\ read f g; printf %s\\n "$f" # <\> <> < < <
<> < <>
# 4 IFS=\\ read f g; printf %s\\n "$f" # <\\> <\> < < <
<\> < <\>
# 5 IFS=\\ read f g; printf %s\\n "$f" # <\^J> <> < <> <
<> <> <>
# 6 IFS=\\ read f g; printf %s\\n "$g" # <\> > > >
>
# 7 IFS=\\ read f g; printf %s\\n "$g" # <\\> \> \> >
>
# 8 IFS=\\ read f g; printf %s\\n "$g" # <\^J>
# 9 IFS=\\ read f; printf %s\\n "$f" # <\> <> <\> <\> <>
<> <> <>
# 10 IFS=\\ read f; printf %s\\n "$f" # <\\> <\> <\\> <\\> <\>
<\> <\> <\>
# 11 IFS=\\ read f; printf %s\\n "$f" # <\^J> <> < <> <>
<> <> <>
# 12 IFS=\\ read -r f g; printf %s\\n "$f" # <\> < < < < <
< <
# 13 IFS=\\ read -r f g; printf %s\\n "$f" # <\\> < < < < <
< <
# 14 IFS=\\ read -r f g; printf %s\\n "$f" # <\^J> < < < < <
< <
# 15 IFS=\\ read -r f g; printf %s\\n "$g" # <\> > > > > >
> >
# 16 IFS=\\ read -r f g; printf %s\\n "$g" # <\\> \> \> \> \>
\> > \>
# 17 IFS=\\ read -r f g; printf %s\\n "$g" # <\^J>
# 18 IFS=\\ read -r f; printf %s\\n "$f" # <\> <\> <\> <\> <\>
<\> <\> <\>
# 19 IFS=\\ read -r f; printf %s\\n "$f" # <\\> <\\> <\\> <\\> <\\>
<\\> <\\> <\\>
# 20 IFS=\\ read -r f; printf %s\\n "$f" # <\^J> < < < <\
<\ < <
Some comments I have:
- bash and dash seem to:
* read the input,
* if -r is not in effect, remove backslashes, except if these are escaped,
* then they should split the input into fields, but they do not (see: #4)
- ksh93 and mksh behave identically, except for #5 and #11 (I think this is an
mksh bug). From POSIX, I think the ksh's are wrong in #9 and #10.
The script I used to generate this is attached.
ifs
Description: Text document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- IFS set to backslash,
Eduardo A . Bustamante López <=