bash command spanning multiple lines with several lines of comments in-between

Bash

Bash Problem Overview


> 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.

Bash Solutions


Solution 1 - Bash

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[@]}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXu WangView Question on Stackoverflow
Solution 1 - BashphininityView Answer on Stackoverflow