Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
for loop with parameter expansion in zsh vs. bash
- X-seq: zsh-users 20886
- From: Alexander Skwar <alexanders.mailinglists+nospam@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: for loop with parameter expansion in zsh vs. bash
- Date: Tue, 3 Nov 2015 07:52:51 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=mMuPPvY6aXu2BasTVuLz3rXyVXrmfuX1cJqhtXZYbAk=; b=nj0o1G627tfVIr4rg88H0trXDjAYBep4dMXAReD7UBcZcPx0IBUrbWPjSFvVPM8BxP 4geGNfD6b94nULi3tUaSK4yDaPqsPem7hbFtgff18D9GF7akDXJLWjU/dcCB7HyS6X2U 6yTbys6P6xtSnwcyUL1paBf3pOoCERzfk1rnWGPcfW0JjzbdpckZvPLVJEaV8jH+7kjv ZFY9igqN/z11u2kBCmBuQQibu/JsPB+Af1yBLSZ3CoFuMKrzBduTv1bvr7jcpmq2AnHf iwdJLhwwTiYvLVZr0lXty2kJZtk0T0/qHnSr4wDPffRVPiKfmFf+y2fTCHeN5QoSCkLF Y8dw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Sender: a.skwar@xxxxxxxxx
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@xxxxxxxxx <==
Messages sorted by:
Reverse Date,
Date,
Thread,
Author