我的預設參數在 bash 腳本中無法運作

我的預設參數在 bash 腳本中無法運作

客觀的:在我的腳本中設定預設訊息來處理對 Bitbucket 的提交

問題:我的控制台回傳錯誤

根據我在谷歌中看到的內容,我嘗試了以下腳本:

commit_message=${1:"checkpoint commit"} 
git add .
git commit -m $commit_message
git push origin 

正如我所說,它回傳一個錯誤,重現如下:

沒有添加任何內容到提交,但未追蹤的文件出現錯誤:src refspec 句柄與任何內容都不符。錯誤:src refspec programmaticScrolling 與任何內容都不符。錯誤:src refspec 調整與任何內容都不符。錯誤:無法將一些參考推送到'https://bitbucket.org/yyyyyyy.git'

答案1

這是一個小文法問題。在bash、 和其他與 POSIX 相容的 shell 中,當使用預設值時,重要的分隔符號不是:,而是-=

commit_message=${1:-"checkpoint commit"} 
git add .
git commit -m "$commit_message"
git push origin

可以在此處找到預設值和替代值的文件:

相關內容