According to the GNU documentationhere all text within single quotes should be interpreted literally. I then tried creating two aliases:
alias alias1='
echo hello'
alias alias2='\
echo hello'
Executing alias1
prints hello
, as I expect. Executing alias2
results in no text being printed. Going into a terminal and manually entering \
, enter, echo hello
also prints hello
. Shouldn't alias2
be identical to my manual test case?
This may be related to a bug fix in bash
4.2. From the change log:
This document details the changes between this version, bash-4.2-alpha, and the previous version, bash-4.1-release.
Changes to Bash
a. Fixed a bug in the parser when processing alias expansions containing quoted newlines.
As far as the definitions go, alias1
should start with a newline, followed by several spaces, then the text echo hello
. alias2
should be nearly identical, with the exception that it does not begin with a newline. Either way, the whitespace preceding echo
is discarded after the alias expansion, during parsing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.