Skip to main content
Typo.
Source Link
Stephen Kitt
  • 482.9k
  • 60
  • 1.2k
  • 1.4k

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotesquoted exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details. So

echo '!' 

also works, and without having to think about where the exclamation mark is.

You can combine single quotes with variable expansion by using printf instead of echo. You can also combine multiple forms of quoting in the same command-line:

echo '!'"$(echo test)" 

In general though, printf is better than echo. As others have mentioned you can also disable history expansion entirely; non-interactive shells don’t enable it by default.

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotes exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details. So

echo '!' 

also works, and without having to think about where the exclamation mark is.

You can combine single quotes with variable expansion by using printf instead of echo. You can also combine multiple forms of quoting in the same command-line:

echo '!'"$(echo test)" 

In general though, printf is better than echo. As others have mentioned you can also disable history expansion entirely; non-interactive shells don’t enable it by default.

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quoted exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details. So

echo '!' 

also works, and without having to think about where the exclamation mark is.

You can combine single quotes with variable expansion by using printf instead of echo. You can also combine multiple forms of quoting in the same command-line:

echo '!'"$(echo test)" 

In general though, printf is better than echo. As others have mentioned you can also disable history expansion entirely; non-interactive shells don’t enable it by default.

Address comments.
Source Link
Stephen Kitt
  • 482.9k
  • 60
  • 1.2k
  • 1.4k

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotes exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details. So

echo '!' 

also works, and without having to think about where the exclamation mark is.

You can combine single quotes with variable expansion by using printf instead of echo. You can also combine multiple forms of quoting in the same command-line:

echo '!'"$(echo test)" 

In general though, printf is better than echo. As others have mentioned you can also disable history expansion entirely; non-interactive shells don’t enable it by default.

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotes exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details.

You can combine single quotes with variable expansion by using printf instead of echo.

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotes exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details. So

echo '!' 

also works, and without having to think about where the exclamation mark is.

You can combine single quotes with variable expansion by using printf instead of echo. You can also combine multiple forms of quoting in the same command-line:

echo '!'"$(echo test)" 

In general though, printf is better than echo. As others have mentioned you can also disable history expansion entirely; non-interactive shells don’t enable it by default.

Source Link
Stephen Kitt
  • 482.9k
  • 60
  • 1.2k
  • 1.4k

You need to escape it or quote it, not both:

echo \! echo "!" 

Bash history expansion ignores escaped exclamation marks, single-quotes exclamation marks, and exclamation marks which appear just before a closing double quote. See the History Interaction section of the manual for details.

You can combine single quotes with variable expansion by using printf instead of echo.