Re: dash & IFS

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

 



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



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux