0

Simply run

echo "This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)"

You get:

bash: ![alt: event not found

Why? It's expected This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)

somenxavier
  • 1,206
  • 3
  • 20
  • 43
  • You can retain the double-quotes as in your example, but prevent history expansion by removing the special treatment of the `!` variable. Add a ``\`` before `!` – Inian Jan 09 '17 at 10:01

2 Answers2

2

use single quotes

echo 'This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)'

single quotes take the test you pass as verbatim. While double quoted strings are interpreted by bash, for instance $VAR would indicate a variable, $(..) would execute a command and insert the stdout, and [...] are treated as boolean evaluator and ! as NOT, and so on. From the bash manual:

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, , \, and, when history expansion is enabled, !. The characters $ and retain their special meaning withindouble quotes. The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or . A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ! appearing in double quotes is escaped using a backslash. The backslash preceding the ! is not removed.

Teudimundo
  • 2,610
  • 20
  • 28
0

The ! is interpreted as the NOT (logical NOT) operator and thus [alt is treated as a command. Using single quotes is probably the best option here:

 echo 'This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)'
P.P
  • 117,907
  • 20
  • 175
  • 238