zsh-users
 help / color / mirror / code / Atom feed
* for loop with parameter expansion in zsh vs. bash
@ 2015-11-03  6:52 Alexander Skwar
  2015-11-03  7:13 ` lilydjwg
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Skwar @ 2015-11-03  6:52 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1769 bytes --]

Hello

I've got a variable, where seperate values are limited with a delimiter.
Let's say PATH with : (but the question is general).

With bash, I can easily create a for loop which loops over all the
elements, when I have bash replace the ":" with a " ", like so: ${PATH//:/
}.

a@ubuntu-notebook:~$ echo $PATH
/home/a/Applications/go/bin:/home/a/bin:/opt/bin:/opt/sbin:/usr/local/sbin:/usr/local/bin:/home/a/Applications/copy/x86_64:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/a/Applications/adt-bundle-linux-x86_64/sdk/platform-tools:/home/a/Applications/btsync:/home/a/.rvm/bin

a@ubuntu-notebook:~$ for e in ${PATH//:/ }; do echo e: $e; done
e: /home/a/Applications/go/bin
e: /home/a/bin
e: /opt/bin
e: /opt/sbin
e: /usr/local/sbin
e: /usr/local/bin
e: /home/a/Applications/copy/x86_64
e: /usr/sbin
e: /usr/bin
e: /sbin
e: /bin
e: /usr/games
e: /usr/local/games
e: /home/a/Applications/adt-bundle-linux-x86_64/sdk/platform-tools
e: /home/a/Applications/btsync
e: /home/a/.rvm/bin


In zsh, the same for loop does not work (like it does in bash):

7:51% for e in ${PATH//:/ }; do echo e: $e; done
e: /home/a/Applications/go/bin /home/a/bin /opt/bin /opt/sbin
/usr/local/sbin /usr/local/bin /home/a/Applications/copy/x86_64 /usr/sbin
/usr/bin /sbin /bin /usr/games /usr/local/games
/home/a/Applications/adt-bundle-linux-x86_64/sdk/platform-tools
/home/a/Applications/btsync


As you can see there, zsh had only 1 iteration of the for loop.

What would be the zsh way to loop over elements, which are delimited by a
":" (or "," or ";" or whatever)?

Thanks a lot,



Alexander
-- 
=>        *Google+* => http://plus.skwar.me         <==
=> *Chat* (Jabber/Google Talk) => a.skwar@gmail.com <==

^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <CADn-QaM6ZEP32i+6t_DC4bA8iJF_VR5hVsP6bMyxqMATxazVCw__45247.5188104019$1446533685$gmane$org@mail.gmail.com>]

end of thread, other threads:[~2015-11-03  8:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03  6:52 for loop with parameter expansion in zsh vs. bash Alexander Skwar
2015-11-03  7:13 ` lilydjwg
2015-11-03  7:49   ` Alexander Skwar
     [not found] <CADn-QaM6ZEP32i+6t_DC4bA8iJF_VR5hVsP6bMyxqMATxazVCw__45247.5188104019$1446533685$gmane$org@mail.gmail.com>
2015-11-03  7:35 ` Stephane Chazelas
2015-11-03  7:47   ` Alexander Skwar
     [not found]   ` <CADn-QaNAt3y2qd4dyBnhd9ifdMOqf9DsVwFbVfdriap6uohvRA__32237.289628438$1446536964$gmane$org@mail.gmail.com>
2015-11-03  8:47     ` Stephane Chazelas

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