Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

osascript

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?

like image 217
myxal Avatar asked Dec 20 '22 20:12

myxal


1 Answers

This means that if argument 1 (${1}) is not set, it will be set to 1.

See parameter substitution here.

 ${parameter-default}, ${parameter:-default}
   If parameter not set, use default.
like image 108
RedX Avatar answered Jan 02 '23 18:01

RedX