Whitespace and Linebreaks
bash
shell scripts are sensitive to whitespace
and linebreaks. Because the “keywords” of this programming language are
actually commands evaluated by the shell, you need to separate arguments
with whitespace. Likewise, a linebreak in the middle of a command will
mislead the shell into thinking the command is incomplete. Follow the
conventions we present here and you should be fine.
If you must break a long command into multiple lines, end each
line (except the last) with a single \
character, which means “continued on next
line”:
➜ grep abcdefghijklmnopqrstuvwxyz file1 file2 \
file3 file4
The slash must be the final character on its line: that is, you
must press Enter immediately after it. Finally, any text following a
hash mark (#
) on a line is a comment.
Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.