문제

I'm having an extremely hard time figuring out how to echo this:

![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

I keep getting this error:

bash: ![alt: event not found

Using double quotes around it does not work. The using single quotes around it does work, however, I also need to echo strings that have single quotes within them. I wouldn't be able to wrap the string with single quotes then.

Is there a way to echo a string of ANY content?

Thanks.

EDIT: Here is some context. I am making a Markdown renderer that grabs the content of a code editor, then appends every line of the code individually into a text file. I am doing this by doing this:

echo TheLineOfMarkdown > textfile.txt
도움이 되었습니까?

해결책

Unlike in many programing languages, '...' and "..." in Bash do not represent "strings" per se; they quote/escape whatever they contain, but they do not create boundaries that separate arguments. So, for example, these two commands are equivalent:

echo foobar
echo "fo"ob'ar'

So if you need to quote some of an argument with single-quotes, and a different part of the argument has to contain single-quotes — no problem.

For example:

echo '![alt text](https://... "What'"'"'s up, Doc?")'

Another option is to use \, which is similar to '...' except that it only quotes a single character. It can even be used inside double-quotes:

echo "\![alt text](https://... \"What's up, Doc?\")"

For more information, see §3.1.2 "Quoting" in the Bash Reference Manual.

다른 팁

! is annoying. My advice: Use \!.

! invokes history completion, which is also performed inside double-quotes. So you need to single-quote the exclamation mark, but as you say that conflicts with the need to not single-quote other single-quotes.

Remember that you can mix quotes:

$ echo '!'"'"'"'
!'"

(That's just one argument.) But in this case, the backslash is easier to type and quite possibly more readable.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top