📄 dollar-at-star
字号:
# first, let's start with the basicsrecho "$@"recho "$*"recho $@recho $*set a brecho "$*"# If IFS is null, the parameters are joined without separatorsIFS=''recho "$*"# If IFS is unset, the parameters are separated by spacesunset IFSrecho "${*}"recho "$@"recho $@IFS='/'set bob 'tom dick harry' joeset $*recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset ${*}recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset $@recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset ${@}recho $#recho $1recho $2recho $3# according to POSIX.2, unquoted $* should expand to multiple words if# $IFS is null, just like unquoted $@IFS=''set bob 'tom dick harry' joeset $*recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset $@recho $#recho $1recho $2recho $3# if IFS is unset, the individual positional parameters are split on# " \t\n" if $* or $@ are unquotedunset IFSset bob 'tom dick harry' joeset $*recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset $@ recho $# recho $1recho $2recho $3# but not for "$@" or "$*"set bob 'tom dick harry' joeset "$*"recho $#recho $1recho $2recho $3set bob 'tom dick harry' joeset "$@"recho $#recho $1recho $2recho $3# POSIX.2 says these should both expand the positional parameters# to multiple wordsset a b c d eIFS=""recho $@recho "$@"# this example is straight from the POSIX.2 rationaleset foo bar bamrecho "$@"recho "$*"unset IFSrecho "$@"recho $@recho "$*"IFS=:# special variablesset -- 1 2 3 4 5 6 7 8 9 10bar=${*}foo=$*echo foo = "$foo"echo bar = "$bar"foo1=$@bar1=${@}echo foo1 = "$foo1"echo bar1 = "$bar1"foo2="$*"bar2="${*}"echo foo2 = "$foo2"echo bar2 = "$bar2"eval foo3='$*' bar3='${*}'echo foo3 = "$foo3"echo bar3 = "$bar3"case $* in*\:*) echo ok 1;;*) echo bad 1;;esaccase $@ in*\:*) echo bad 2;;*) echo ok 2;;esaccase "$*" in*\:*) echo ok 3;;*) echo bad 3;;esaccase "$@" in*\:*) echo bad 4;;*) echo ok 4;;esacIFS=$' \t\n'bar=${*}foo=$*echo foo = "$foo"echo bar = "$bar"foo1=$@bar1=${@}echo foo1 = "$foo1"echo bar1 = "$bar1"foo2="$*"bar2="${*}"echo foo2 = "$foo2"echo bar2 = "$bar2"eval foo3='$*' bar3='${*}'echo foo3 = "$foo3"echo bar3 = "$bar3"case $* in*\ *) echo ok 1;;*) echo bad 1;;esaccase $@ in*\ *) echo ok 2;;*) echo bad 2;;esaccase "$*" in*\ *) echo ok 3;;*) echo bad 3;;esaccase "$@" in*\ *) echo ok 4;;*) echo bad 4;;esac# tests for special expansion of "$*" and "${array[*]}" when used with other# expansions -- bugs through bash-2.05b${THIS_SH} ./dollar-star1.sub# tests for expansion of "$@" on rhs of things like ${param:+word}. Bugs# though bash-2.05b${THIS_SH} ./dollar-at1.sub# tests for expansion of other variables in double-quoted strings containing# $@. Bugs through bash-2.05b${THIS_SH} ./dollar-at2.sub# tests for various expansions of $* in different contexts -- word split,# no splitting, etc. when $IFS is NUL${THIS_SH} ./dollar-star2.sub# tests for expansions of "${array[*]}" and "${array[@]}" when $IFS is not the# default and the array contains null elements${THIS_SH} ./dollar-star3.sub# test for set -u and expansions of $@ when there are no positional parameters${THIS_SH} ./dollar-at3.sub# test for set -u and expansions of $* when there are no positional parameters${THIS_SH} ./dollar-star4.sub# tests for expansions of $* when IFS is null${THIS_SH} ./dollar-star5.subexit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -