bug-bash
[Top][All Lists]
Advanced

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

Re: RFC: turn off word splitting for vars but keep for read


From: Peggy Russell
Subject: Re: RFC: turn off word splitting for vars but keep for read
Date: Fri, 22 Nov 2013 23:52:22 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

> ...
> $ IFS=""
> $ f() { echo $1; }; x="a b c"; f $x
> a b c
> 
> But, IFS influences `read`, which of course benefits from word
> splitting. In light of that conflict, I propose two possible
> solutions:
> 
> 1: shopt -s unsplit_vars
> 
> which will turn off word splitting for var expansion.
> 
> or 2: new IFS2 var that will override IFS for `read` (i.e. `read` will
> use IFS2 when IFS is unset).
> 

Could also do:

  IFS=$'\n\t' 

  echo "Checking..."; echo -n "$IFS"|hexdump

The IFS on the read could be considered script documentation for
the contents of the current file. Similar to awk's FS.

  while IFS=: read -re line; do : ; done  < file

Interesting read here, but pertains to splitting and filenames:
http://www.dwheeler.com/essays/filenames-in-shell.html
But could perhaps provide a supportive argument, maybe, for your suggestion
option #1. http://mywiki.wooledge.org/Quotes is helpful.

Peggy Russell





reply via email to

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