Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: (some tips about variables) Re: avoid eval?



On 13/03/18 09:36 AM, Marc Chantreux wrote:

you should be carreful to reduce the scope of the change of such an
important variable. more generally, you should localize every variables
of the functions using local.

Right, as Eric also suggested.
     setopt warncreateglobal nounset
That's an entirely new idea, I'll study it.
* keep the IFS change as tight as possible by setting it for only one
   read. exemples

     getent passwd |
         while {IFS=: read login _ uid gid gecos home shell } {
             [[ $shell == *zsh* ]] && print $login is cool
         }

Well, it it can be *that* local, just for one loop, then that makes things much simpler.

Still there are mysteries:

function test ()
{
local IFS=$'\n'
echo $path[2]
tty=( `stty size` )         # Grab the size of the terminal.
echo $tty
echo $tty[1]
local IFS=' '
echo $path[2]
tty=( `stty size` )         # Grab the size of the terminal.
echo $tty
echo $tty[1]
}

$ . ./test; test
/aWorking/Zsh/System
52 80
52 80
/aWorking/Zsh/System
52 80
52



... $path is space-separated, yet it is 'immune' to IFS issues. Array $tty, it is not immune to IFS.  I suspect that's because maybe $path is not an array, and it would appear that IFS only applies to arrays (?) but if so, how does one tell one from the other?  It seems counter intuitive that "$tty[1]" and "$tty" could mean the same thing in any situation.  Splitting issues seem the one thing that is always hard to get right, there seem to be dozens of variations on the theme.



Messages sorted by: Reverse Date, Date, Thread, Author