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.
In Shell or Bash shell, we can comment on multiple lines using << and name of comment. we start a comment block with << and name anything to the block and wherever we want to stop the comment, we will simply type the name of the comment.
To split long commands into readable commands that span multiple lines, we need to use the backslash character (\). The backslash character instructs bash to read the commands that follow line by line until it encounters an EOL.
Although Bash has various escape characters, we only need to concern ourselves with \n (new line character). For example, if we have a multiline string in a script, we can use the \n character to create a new line where necessary.
Using a Backslash. The backslash (\) is an escape character that instructs the shell not to interpret the next character. If the next character is a newline, the shell will read the statement as not having reached its end. This allows a statement to span multiple lines.
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[@]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With