I have a simple program to print the command line arguments in zsh. However, I see different behaviour with printf vs echo. Can anyone explain?
#!/bin/zsh
echo "$# @ : "$@" "
printf "\n"
printf "$# * $* "
printf "\n"
printf "$# @ : "$@" \n"
Output:
batman$ ./args a b c d
4 @ : a b c d
4 * a b c d
4 @ : abatman$ //also gobbles up the newline!!
batman$
echoandprintf(andprint) are different commands with different syntaxes and behaviors. Read the documentation for more info:echoprintprintfIn Zsh, you should always prefer
printorprintfoverecho.echois mostly just there for compatibility with other shells.