linux - echo ${1 +"$@"} 是什么意思

标签 linux shell erlang

来自/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/

相关文章:

tcp - 如何检测 tcp 客户端与 gen_tcp 断开连接?

erlang - 如何在 Erlang 中创建可变数量的函数?

linux - 无需重启 sshd 即可为授权用户添加 key

linux - 从制表符分隔的文件中提取最后一列

linux - 无法打开与身份验证代理的连接(REVIEW)

PHP shell_exec ('whoami; ls/var/lib/nagios3 2>&1' );权限被拒绝,但在 shell 中正常

bash - bin/activate 脚本的 "source"是什么意思?

erlang - 当内部和外部 IP 地址起作用时连接 Erlang 节点

windows - 在 MiniCPAN 镜像上运行 CPAN::Tarzip 的问题

python - shell 脚本 : Execute a python program from within a shell script