if type:
echo "1 dquote> 2 quick dquote> 3 brown" | while read -a d; echo "${d[1]}--${d[0]}"; done in bash says:
the--1 quick--2 brown--3 but in zsh says:
zsh: bad option: -a why? , should instead?
in both shells read builtin. shares same purpose, implementation , options differ.
in order read in array in zsh, read requires option -a (instead of -a):
echo "1 2 quick 3 brown" | while read -a d; echo $d[2]--$d[1]; done note: there many more differences between zsh , bash:
- in
zsharrays numbered 1 default, inbashstart zero. echo $arrayprints outputs elements inzshfirst element inbash- to print third element of array in
shcan useecho $array[3]. inbashbraces needed delimit subscript, subscript third element2:echo ${array[2]}. in
zshnot need quote parameter expansions in order handle values white spaces correctly. examplefilename="no such file" cat $filenamewill print 1 error message in
zsh:cat: 'no such file': no such file or directorybut 3 error messages in
bash:cat: no: no such file or directory cat: such: no such file or directory cat: file: no such file or directoryin
zshbuiltinechoevaluates escape codes default. inbashneed pass-eargument that.echo 'foo\tbar'zsh:foo barbash:foo\tbar…
generally, important keep in mind that, while zsh , bash similar, far being same.
Comments
Post a Comment