* dash & IFS
@ 2020-03-23 8:20 n8dandy
2020-03-23 8:44 ` Harald van Dijk
0 siblings, 1 reply; 3+ messages in thread
From: n8dandy @ 2020-03-23 8:20 UTC (permalink / raw)
To: dash
[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]
Good morning,
Few days ago, I noticed something strange with dash and IFS. It was
verified with the following versions :
- 0.5.10.2 on Voidlinux
- 0.5.10.2 on Debian Buster
- 0.5.8 on Ubuntu 18.04.2 LTS (Bionic Beaver)
Here the issue :
$ ls
file.sign file1 file2 other.sign whileifs*
$ cat whileifs
#!/bin/dash
find . -type f | sort -d | while IFS=$'\n' read -r F; do
printf "%s\n" "$F"
done
$ ./whileifs
./file1
./file2
./file.sig
./other.sig
./whileifs
file.sig and other.sig are returned instead of file.sign and other.sign.
Here the result with bash :
$ bash whileifs
./file1
./file2
./file.sign
./other.sign
./whileifs
Here the result with mksh :
$ mksh whileifs
./file1
./file2
./file.sign
./other.sign
./whileifs
Here the result with lksh :
$ lksh whileifs
./file1
./file2
./file.sign
./other.sign
./whileifs
Here the result with busybox ash (1.31.0) :
$ /tmp/busybox-x86_64 ash whileifs
./file1
./file2
./file.sign
./other.sign
./whileifs
I attached the test directory. Can you reproduce it ?
Sincerely
Y
[-- Attachment #2: dashifs.tar.gz --]
[-- Type: application/gzip, Size: 318 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dash & IFS
2020-03-23 8:20 dash & IFS n8dandy
@ 2020-03-23 8:44 ` Harald van Dijk
2020-03-25 7:08 ` n8dandy
0 siblings, 1 reply; 3+ messages in thread
From: Harald van Dijk @ 2020-03-23 8:44 UTC (permalink / raw)
To: n8dandy, dash
On 23/03/2020 08:20, n8dandy wrote:
> Good morning,
>
> Few days ago, I noticed something strange with dash and IFS. It was
> verified with the following versions :
>
> - 0.5.10.2 on Voidlinux
> - 0.5.10.2 on Debian Buster
> - 0.5.8 on Ubuntu 18.04.2 LTS (Bionic Beaver)
>
> Here the issue :
>
> $ ls
> file.sign file1 file2 other.sign whileifs*
> $ cat whileifs
> #!/bin/dash
>
> find . -type f | sort -d | while IFS=$'\n' read -r F; do
> printf "%s\n" "$F"
> done
This isn't about IFS, this is just because dash does not support the use
of $'\n' to indicate a newline. In dash, $'\n' is equivalent to '$\n'
(in the same way that x'y' is equivalent to 'xy' in all shells). To
portably get a string consisting of a single newline, either put a
literal newline in your source:
nl='
'
or use command substitutions:
nl=$(printf '\n.'); nl=${nl%.}
Currently, $'...' is not part of POSIX (although it has been accepted
for the next version), and dash tends not to add new features that are
not part of the standard.
Cheers,
Harald van Dijk
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dash & IFS
2020-03-23 8:44 ` Harald van Dijk
@ 2020-03-25 7:08 ` n8dandy
0 siblings, 0 replies; 3+ messages in thread
From: n8dandy @ 2020-03-25 7:08 UTC (permalink / raw)
To: Harald van Dijk; +Cc: dash
On Monday, 23 March 2020 09:44, Harald van Dijk <harald@gigawatt.nl> wrote:
> On 23/03/2020 08:20, n8dandy wrote:
> This isn't about IFS, this is just because dash does not support the use
> of $'\n' to indicate a newline. In dash, $'\n' is equivalent to '$\n'
> (in the same way that x'y' is equivalent to 'xy' in all shells). To
> portably get a string consisting of a single newline, either put a
> literal newline in your source:
>
> nl='
> '
>
> or use command substitutions:
>
> nl=$(printf '\n.'); nl=${nl%.}
>
> Currently, $'...' is not part of POSIX (although it has been accepted
> for the next version), and dash tends not to add new features that are
> not part of the standard.
Thanks for your help. Even if $'...' is not POSIX, I thought dash already
supports it. I'll stick with IFS= instead.
Sincerely
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-25 7:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 8:20 dash & IFS n8dandy
2020-03-23 8:44 ` Harald van Dijk
2020-03-25 7:08 ` n8dandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).