3 ms·
Does any POSIX-like shells do arrays nicely? Fish has "string split": $ string split ", " "Paris, France, Europe" Paris France Europe Murex h
by hnlmorg 5y ago
Does any POSIX-like shells do arrays nicely?
Fish has "string split":
$ string split ", " "Paris, France, Europe"
Paris
France
Europe
Murex has "jsplit":
» echo "Paris, France, Europe" -> jsplit ", "
[
"Paris",
"France",
"Europe"
]
But neither are really Bash compatible. Is zsh any better?
- JNRowe 5y agoI wouldn't - you know - use this, but with zsh… $ print -l ${(s:, :):-Paris, France, Europe} Paris France Europe I won't try to answer the "is zsh any better?" question with this response either ;)
- psacawa 5y agozsh has so-called expansion modifiers that do this. For example string="Paris, France, Europe" arr=(${(s:, :)string}) for x in $arr; do echo "<$x>"; done <Paris> <France> <Europe>