加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Shell - difference between '\[emailprotected

发布时间:2020-12-16 01:38:59 所属栏目:安全 来源:网络整理
导读: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

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 (a,?b 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读