Bash Script Help - File Names With Spaces -- SOLVED

Anonymous swell.k at gmail.com
Wed Aug 18 00:37:12 UTC 2010


Drew Tomlinson <drew at mykitchentable.net> writes:

> It finally occurred to me that I needed the shell to see a new line as
> the delimiter and not whitespace. Then a simple search revealed my
> answer:
>
> O=$IFS
> IFS=$(echo -en "\n\b")
> <do stuff>
> IFS=$O

Old IFS value can be preserved by using `local' keyword or (...) braces, too.
It's a bit better than polluting global scope with temporary variable.

  $ echo -n "$IFS" | (vis -w; echo)
  \040\^I\^J

  $ for i in $(find . -type f); do echo $i; done
  ./My
  Long
  File
  Name
  ./Another
  File

  $ f() { local IFS=; eval "$@"; }
  $ f 'for i in $(find . -type f); do echo $i; done'
  ./My Long File Name
  ./Another File

  $ (IFS=; for i in $(find . -type f); do echo $i; done)
  ./My Long File Name
  ./Another File

  $ echo -n "$IFS" | (vis -w; echo)
  \040\^I\^J


More information about the freebsd-questions mailing list