5

我正在阅读这里的脚本并试图了解发生了什么。此函数执行更改 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';\
};\

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

4

1 回答 1

12

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

请参阅此处的参数替换

 ${parameter-default}, ${parameter:-default}
   If parameter not set, use default.
于 2013-12-30T09:25:06.047 回答