dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: n8dandy <n8dandy@protonmail.com>,
	"dash@vger.kernel.org" <dash@vger.kernel.org>
Subject: Re: dash & IFS
Date: Mon, 23 Mar 2020 08:44:52 +0000	[thread overview]
Message-ID: <0a54e6bd-07e7-80f0-a503-149473a19835@gigawatt.nl> (raw)
In-Reply-To: <dDYpzKRWD9p1jhFjsIjWZvAddv8e0CQYDq1UxXsV33DN8SvAxPj9gOakBk9LBcTu6j_qEZLUTIoebSKq3-yQ4LKNjGZG-jk-SMMy_RGE-hI=@protonmail.com>

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

  reply	other threads:[~2020-03-23  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23  8:20 n8dandy
2020-03-23  8:44 ` Harald van Dijk [this message]
2020-03-25  7:08   ` n8dandy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a54e6bd-07e7-80f0-a503-149473a19835@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=dash@vger.kernel.org \
    --cc=n8dandy@protonmail.com \
    --subject='Re: dash & IFS' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).