来自/usr/local/bin/erl
ROOTDIR=/usr/local/lib/erlang
BINDIR=$ROOTDIR/erts-5.9.1/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
export EMU
export ROOTDIR
export BINDIR
export PROGNAME
exec $BINDIR/erlexec ${1+"$@"}
我知道 "$@"meams 参数。但是 {1+"$@"} 是什么意思?
最佳答案
来自 IEEE 标准 1003.1(POSIX 2013),Shell command language :
${parameter:+[word]}
Use Alternative Value. If parameter is unset or null, null shall be substituted; otherwise, the expansion of word (or an empty string if word is omitted) shall be substituted.
即,${1+"$@"}
扩展为 "$@"
的值,命令行参数,除非 $1
未设置,即没有命令行参数,在这种情况下,表达式将展开为空。显示其工作原理的更简单的脚本是
echo '"' ${1+"$@"} '"'
如果将其存储在文件 test.sh
中并运行它,您会得到:
/tmp$ sh test.sh
" "
/tmp$ sh test.sh 1
" 1 "
/tmp$ sh test.sh 1 2
" 1 2 "
(开头和结尾的空格来自echo
。)
关于linux - echo ${1 +"$@"} 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19274367/