Trouble understanding parameter substitution in a script

后端 未结 1 902
广开言路
广开言路 2021-01-24 20:41

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:-         


        
相关标签:
1条回答
  • 2021-01-24 21:46

    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.

    0 讨论(0)
提交回复
热议问题