bash中$ {1-1}是什么意思?

myx*_*xal 1 bash osascript

我正在从这里阅读脚本并试图了解正在发生的事情.此函数执行更改Finder窗口的目录:

function ee { 
 osascript -e 'set cwd to do shell script "pwd"'\
 -e 'tell application "Finder"'\
 -e "if (${1-1} <= (count Finder windows)) then"\
 -e "set the target of window ${1-1} to (POSIX file cwd) as string"\
 -e 'else' -e "open (POSIX file cwd) as string"\
 -e 'end if' -e 'end tell';\
};\
Run Code Online (Sandbox Code Playgroud)

我假设$由bash解释,因为它在双引号内.我一直无法找到可能{1-1}意味着什么.我在单独的测试脚本中使用了表达式但是找不到与plain的区别$1.有任何想法吗?

Red*_*edX 6

这意味着如果${1}未设置参数1(),请将值设置为1.

请参见参数替换.

 ${parameter-default}, ${parameter:-default}
   If parameter not set, use default.
Run Code Online (Sandbox Code Playgroud)

  • +1,只是一个注释:我被建议[这里](http://stackoverflow.com/questions/20783187/remove-a-word-from-a-string-in-bash-shell-linux/20783245#comment31159567_20783245)那个,"ABS不是一个很好的参考 - 它在它的例子中显示了很多不好的做法.最好在mywiki.wooledge.org/BashFAQ/073指出人们" (2认同)