Reputation: 7907
I'm trying to understand a bash script whose first four lines are:
#!/bin/sh
SCRIPT="`basename $0 | sed 's/\..*$//'`"
CONFIG=${1:-$HOME/.$SCRIPT}
DIR=${2:-$HOME/Documents}
I understand that the last two lines are doing parameter substitution on paths input as script arguments 1 and 2, but I've been unable to figure out how this works (e.g. here). What does the ":-" part mean? Sorry for the newbie question.
Upvotes: 1
Views: 104
Reputation: 36229
From man bash
:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Other‐
wise, the value of parameter is substituted.
Very easy to find, with man bash
, and then /:-
. The slash introduces a search, and :-
is just the content to search for. Else, searching in bash can get very boring, because it is huge, but here it is the first hit.
Upvotes: 2