As far as I know, it is not possible, for Bash tries to follow to POSIX guidelines and other standards. Especially:
If a
<newline>
follows the backslash, the shell shall interpret this as line continuation. The backslash and<newline>
s shall be removed before splitting the input into tokens. Since the escaped<newline>
is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.
— Shell Command Language, 2.2.1 Escape Character (Backslash)
Thus, it is not possible because of how the shell parser works:
- A line starting with
#
is a comment, and nothing after gets evaluated (including a trailing\
) - A
\
that is not at the end of a line, is not a line skip.
In your script:
ls -l \
-a \
# comment here
-h \
-t .
The comment line is replaced with nothing (i.e. it has no token); and since the command, so far, is valid, and as a newline is met (… -a ↵
), the shell runs the ls -l -a
command, then the -h -t .
command (and does not find a -h
binary in your $PATH
, so it stops right there.)