【发布时间】:2013-12-30 09:20:05
【问题描述】:
我正在阅读来自here 的脚本并试图了解发生了什么。此函数执行更改 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} 的含义。我已经在单独的测试脚本中使用过该表达式,但找不到与普通 $1 的区别。有什么想法吗?
【问题讨论】:
-
我相信这是一个“默认”。如果用户提供了一个命令行参数,那么
${1-1}将扩展为该参数,否则它将简单地扩展/“默认”为连字符之后的任何内容——在你的情况下为1。