zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: (some tips about variables) Re: avoid eval?
Date: Tue, 13 Mar 2018 10:50:17 -0700	[thread overview]
Message-ID: <32661718-eaa2-a270-9b88-69156f7ddfe6@eastlink.ca> (raw)
In-Reply-To: <20180313163634.s4qvlfhdzqplxn4s@prometheus.u-strasbg.fr>

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.


  reply	other threads:[~2018-03-13 17:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-11 20:48 Ray Andrews
2018-03-11 22:53 ` Marc Chantreux
2018-03-12  0:43   ` Ray Andrews
2018-03-13  2:13     ` Ray Andrews
2018-03-13  2:17       ` Eric Cook
2018-03-13 16:36       ` (some tips about variables) " Marc Chantreux
2018-03-13 17:50         ` Ray Andrews [this message]
2018-03-13 20:39           ` Marc Chantreux
2018-03-13 21:50             ` Ray Andrews

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=32661718-eaa2-a270-9b88-69156f7ddfe6@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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