Welcome to the world of quoting and quoting surprises.
The main issue is that zsh doesn't split on IFS characters by default.
In that: it is different from all other shells.
To test how quoting change the way shells work we need code that tests both quoted and unquoted versions of your code.
Your code (adding a couple of variables):
program() { printf '%02d-1: %6s 2: %6s 3: %6s' "$i" "$1" "$2" "$3"; }
runa() { program "$@" ; }
run1() { echo "`runa $1 $2 $3 `"; }
run1 'a b' c
Let me expand on the details.
Let's assume that you create a local sh link pointing to where zsh lives:
ln -s "/usr/bin/zsh" ./sh
And, also, let's assume you copy the following script to a so file.
An script repeating each function with quoted and unquoted variables:
program() { printf '%02d-1: %6s 2: %6s 3: %6s' "$i" "$1" "$2" "$3"; }
runa() { program "$@"; }
runb() { program $@ ; }
run1() { echo "`runa "$1" "$2" "$3"`"; }
run2() { echo "`runb "$1" "$2" "$3"`"; }
run3() { echo "`runa $1 $2 $3`"; }
run4() { echo "`runb $1 $2 $3`"; }
for i in `seq 4`; do
run"$i" 'a b' c
done
Then, On execution, we get this printed:
# Any shell (except zsh) results.
01-1: a b 2: c 3:
02-1: a 2: b 3: c
03-1: a 2: b 3: c
04-1: a 2: b 3: c
Only the first run (run1), where all is quoted, keeps 'a b' joined.
However, zsh acts as if all has been quoted all the time:
# ZSH results.
01-1: a b 2: c 3:
02-1: a b 2: c 3:
03-1: a b 2: c 3:
04-1: a b 2: c 3:
zsh in emulation.
It is supposed that zsh will emulate older shells if called as sh or ksh.
But in practice this is not always true:
$ ./sh ./so # emulated sh
01-1: a b 2: c 3:
02-1: a b 2: c 3:
03-1: a 2: b 3: c
04-1: a 2: b 3: c
The second line is different than the second line for any other shell.
It is a good idea to read the answers to this question
zshthough – Eric Renouf Sep 23 '16 at 16:43