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
zsh
arrays numbered 1 default, inbash
start zero. echo $array
prints outputs elements inzsh
first element inbash
- to print third element of array in
sh
can useecho $array[3]
. inbash
braces needed delimit subscript, subscript third element2
:echo ${array[2]}
. in
zsh
not need quote parameter expansions in order handle values white spaces correctly. examplefilename="no such file" cat $filename
will print 1 error message in
zsh
:cat: 'no such file': no such file or directory
but 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 directory
in
zsh
builtinecho
evaluates escape codes default. inbash
need pass-e
argument that.echo 'foo\tbar'
zsh
:foo bar
bash
:foo\tbar
…
generally, important keep in mind that, while zsh
, bash
similar, far being same.
Comments
Post a Comment