help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] IFS can not be made local?


From: Greg Wooledge
Subject: Re: [Help-bash] IFS can not be made local?
Date: Fri, 26 Feb 2016 07:20:29 -0500
User-agent: Mutt/1.4.2.3i

On Thu, Feb 25, 2016 at 03:12:00PM -0600, Peng Yu wrote:
> Hi, The following example shows that IFS can not be set local.

It can be.

> function cmd {
> local IFS
> IFS=:
> x=($1)
> printf "%s\n" "address@hidden"
> }

This, however, is not wise.  An unquoted $1 is still subject to filename
expansion, which could lead to highly unexpected results.

cmd() {
  IFS=: read -r -a x <<< "$1"
  printf "<%s> " "address@hidden"; echo
}

Or, if you need to handle an input string with embedded newlines:

cmd() {
  IFS=: read -r -d '' -a x < <(printf %s "$1")
  printf "<%s> " "address@hidden"; echo
}



reply via email to

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