What does ${1-1} in bash mean?

无人久伴 提交于 2020-01-06 01:37:26

问题


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';\
};\

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:


This means that if argument 1 (${1}) is not set, set the value to 1.

See parameter substituiton here.

 ${parameter-default}, ${parameter:-default}
   If parameter not set, use default.


来源:https://stackoverflow.com/questions/20836612/what-does-1-1-in-bash-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!