Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use comments when the line is split with backslashes?

Tags:

bash

shell

sh

I’d like to embed comments like this

ls -l \
-a \
# comment here
-h \
-t . 

But it seems that’s not possible. Maybe some other variant does exist? Putting a comment right after the backslash or ending a comment with a backslash doesn’t help.

like image 401
tijagi Avatar asked May 11 '14 10:05

tijagi


People also ask

How do you continue a comment on a different line in Python?

You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line.

How do you comment multiple lines in Shell?

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.


1 Answers

The posts above do not have a direct solution. However, there is a direct solution that's actually mentioned in even older posts: How to put a line comment for a multi-line command and Commenting in a Bash script.

The solution I like best is:

ls -l `# long format` \
-a `# all files` \
-h `# human readable` \
-t `# time sort`

You will need both the accent grave (`) quotation and the octothorpe (#) to indicate the comment. Use them before the backslash.

like image 113
LC-datascientist Avatar answered Oct 27 '22 00:10

LC-datascientist