Shell - difference between '\[email protected]" and "\$*"

There are no difference between $* and [email protected],but there is a difference between "[email protected]" and "$*".

$ cat 1.sh mkdir "$*" $ cat 2.sh mkdir "[email protected]" $ sh 1.sh a "b c" d $ ls -l total 12 -rw-r--r-- 1 igor igor 11 mar 24 10:20 1.sh -rw-r--r-- 1 igor igor 11 mar 24 10:20 2.sh drwxr-xr-x 2 igor igor 4096 mar 24 10:21 a b c d

We gave three arguments to the script (ab c and d) but in "$*" they all were merged into one argument a b c d.

$ sh 2.sh a "b c" d $ ls -l total 24 -rw-r--r-- 1 igor igor 11 mar 24 10:20 1.sh -rw-r--r-- 1 igor igor 11 mar 24 10:20 2.sh drwxr-xr-x 2 igor igor 4096 mar 24 10:21 a drwxr-xr-x 2 igor igor 4096 mar 24 10:21 a b c d drwxr-xr-x 2 igor igor 4096 mar 24 10:21 b c drwxr-xr-x 2 igor igor 4096 mar 24 10:21 d

You can see here,that "$*" means always one single argument,and "[email protected]" contains as many arguments,as the script had. "[email protected]" is a special token which means "wrap each individual argument in quotes". So a "b c" d becomes (or rather stays) "a" "b c" "d" instead of "a b c d" ("$*") or "a" "b" "c" "d" ([email protected] or $*).

copied from: https://stackoverflow.com/questions/15596826/what-is-the-difference-between-and-in-shell-script

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...