什么是$ {} 1-1在bash是什么意思? [英] What does ${1-1} in bash mean?

查看:233
本文介绍了什么是$ {} 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.

这篇关于什么是$ {} 1-1在bash是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆