2012-10-10 33 views
31
在兩者之間

可能重複:
Bash: How to Put Line Comment for a Multi-line Commandbash命令跨越多行與註釋幾行

我願做這樣的事情

sudo apt-get install \ 
    #a very long description 
    #of the package 
    #that spans multiple lines 
    pkg1 \ #maybe I want an inline comment also 
    #another description that 
    #spans multiple lines 
    pkg2 

注我不只對apt-get命令感興趣。

+0

你有沒有試過把這個放在shell腳本中並運行它? – sofly

+0

@SoFLy是的,我得到錯誤。 –

+0

這篇帖子指出可能的重複問題是關於在線評論。我對多行評論感興趣。但是同樣的解決方法確實有效。謝謝。 –

回答

56

據我所知,Bash在單個命令中忽略了'#'後面的所有內容,並且multilining不會改變它。然而,你可能可以使用bash陣列達到相同的表達水平:

packagelist=(
    package1 # Inline Comments 
    # Multiline Comments too 
    package2 
    # Package description goes here 
    # Detailed descriptions.. 
) 
sudo apt-get install ${packagelist[@]} 
+1

謝謝你的回答。 –

+0

不錯...這也允許空行。 –