什么是$ {} 1-1在bash是什么意思?
问题描述:
我是从这里阅读剧本,并试图了解是什么怎么回事。这个函数执行更改Finder窗口的目录:
I'm reading the scripts from here and trying to understand what's going on. This function performs changing the directory of a Finder window:
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的PTED间$ P $,因为它是双引号内。我一直没能找到什么可以 {1-1}
的意思。我打在单独的测试脚本前pression却找不到从普通的差异 $ 1
。任何想法?
I'm assuming the $
is interpreted by bash, since it's inside double-quotes. I haven't been able to find what could {1-1}
mean. I've played with the expression in separate test scripts but couldn't find a difference from plain $1
. Any ideas?
答
这意味着,如果参数1( $ {1}
)没有设定,设定值1。
This means that if argument 1 (${1}
) is not set, set the value to 1.
请参阅参数substituiton这里。
${parameter-default}, ${parameter:-default}
If parameter not set, use default.