2012-04-23 27 views
1

我試圖理解一個bash script其前四個行是:無法理解參數替代

#!/bin/sh 
SCRIPT="`basename $0 | sed 's/\..*$//'`" 
CONFIG=${1:-$HOME/.$SCRIPT} 
DIR=${2:-$HOME/Documents} 

據我瞭解,最後兩行是在路徑輸入作爲腳本參數做參數替換1和2,但我一直無法弄清楚這是如何工作的(例如here)。 「: - 」部分是什麼意思?對不起,新手問題。

回答

2

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. 

很容易找到,與man bash,然後/:-。斜線引入搜索,而:-只是搜索的內容。否則,在bash中搜索會變得非常無聊,因爲它非常龐大,但這裏是第一次。

+0

道歉。沒有想到看起來_there_。 – telliott99 2012-04-23 20:00:53