56

Possible Duplicate:
Bash: How to Put Line Comment for a Multi-line Command

I would like to do something like this

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

Note that I'm not just interested in the apt-get command.

Community
  • 1
  • 1
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
  • have you tried putting this in a shell script and running it? – sofly Oct 10 '12 at 07:59
  • The post pointed to as a possible duplicate asks about in-line comments. I was interested in multi-line comments. But the same workaround there does work. Thanks. – Xu Wang Oct 10 '12 at 11:14

1 Answers1

104

As far as I know Bash ignores everything after the '#' in a single command, and multilining won't change that. However you can probably achieve the same level of expression using bash arrays:

packagelist=(
  package1 # Inline Comments
  # Multiline Comments too
  package2
  # Package description goes here
  # Detailed descriptions..
)
sudo apt-get install ${packagelist[@]}
phininity
  • 1,673
  • 2
  • 14
  • 9