LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Another thread about escaping an exclamation point in bash. (https://www.linuxquestions.org/questions/programming-9/another-thread-about-escaping-an-exclamation-point-in-bash-816488/)

pr_deltoid 06-26-2010 05:57 AM

Another thread about escaping an exclamation point in bash.
 
I saw another thread here about this, and did some reading and googling and came to this conclusion:
You need to use single quotations. Am I missing something here? You can't use an apostrophe and an exclamation point together in an interactive shell?
Quote:

prdeltoid@home:~$ echo "I'd say: \"Go for it!\""
bash: !\"": event not found
prdeltoid@home:~$ echo 'I'd say: "Go for it!"'
bash: !"': event not found
prdeltoid@home:~$ echo "I'd say: \"Go for it\!\""
I'd say: "Go for it\!"
And so on. Very strange... I'm not complaining about this, but it's very strange that you can't have a combination of an apostrophe and an exclamation point no matter what you try. But at least in scripts, this isn't true... I guess it's not a big deal at all...

wje_lq 06-26-2010 06:02 AM

Code:

echo I\'d say: \"Go for it\!\"

pr_deltoid 06-26-2010 06:05 AM

#*$!@*! :doh:
I don't know why I didn't just think of that... I kept thinking "quotations, backslash, quotations, backslash". :doh: Thanks for pointing that out to me. I was just reading an example not long ago that wasn't using quotation marks, and for some reason I was sitting here unable to think of why I couldn't get this to work. I'm sleepy.

ntubski 06-26-2010 11:01 AM

You can turn off history ("!") expansion:

Code:

~$ echo "I'd say: \"Go for it!\""
bash: !\"": event not found
~$ set +o histexpand
~$ echo "I'd say: \"Go for it!\""
I'd say: "Go for it!"


everToulouse 06-26-2010 03:27 PM

Code:

echo "I'd say: \"Go for it"'!'"\""
I'd say: "Go for it!"



All times are GMT -5. The time now is 08:42 AM.