Can comments be used when the line is split into a backslash?

I like to insert comments like this

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

But it seems to be impossible. Maybe some other option exists? Putting a comment immediately after a backslash or ending a comment with a backslash does not help.

+4
source share
7 answers

As far as I know, this is not possible because Bash is trying to follow POSIX guidelines and other standards. Special:

a <newline> , . <newline> . <newline> , .
- , 2.2.1 ( )

, - , :

  • , #, , , ( )
  • A \, , .

script:

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

(.. ); , (… -a ↵) ls -l -a, -h -t . ( -h $PATH, .)

+3

-

ls -l  -a  -h  -t .  
#  |   |   |   time sort
#  |   |   human readable
#  |   all files
#  long format

, , . --human-readable, -h.

+2

, , . ( .)

cmd_options=(
  -l
  -a
   # comment here
  -h
  -t .
)
ls "${cmd_options[@]}" 
+1

- , :

ls_cmd=(
  ls
  -l  # long form
  -a  # show hidden files
  -h  # human-readable sizes
  -t  # sort by time
  .
)

"${ls_cmd[@]}" # run the command from the array

... - .

+1

, , , , .

# commenting \
seveal lines

# :

# commenting
# seveal lines

, :

: 'This is almost
a multiline comment'

, , 0.

0

. , - , :

ls \
# -l \
-h

-l , ls -h .

Because in C-like languages ​​you have comments with borders: /* */you can put those between the tokens in an expression that uses line continuation.

0
source

... and this can be done after the pipes:

echo "Hello beautiful" | \
# Display match only:
grep -o beautiful

But otherwise ... no.

0
source

Source: https://habr.com/ru/post/1540094/


All Articles