无法理解参数替代在脚本 [英] Trouble understanding parameter substitution in a script
问题描述
我想了解一个bash的脚本其前四个行是:
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}
据我了解,最后两行的路径上输入作为脚本参数1和2做参数替代,但我一直无法弄清楚如何工作(如的这里)。什么是 - 的一部分呢?很抱歉的新手问题。
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.
推荐答案
从男人庆典
:
${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.
很容易找到,与男人庆典
,然后<大骨节病> / 骨节病> : -
。斜线引入了搜索,并: -
仅仅是要搜索的内容。否则,在bash搜索可以得到非常无聊,因为它是巨大的,但在这里它是先打。
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.
这篇关于无法理解参数替代在脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!