LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-26-2010, 06:57 AM   #1
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
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...

Last edited by pr_deltoid; 06-26-2010 at 07:02 AM.
 
Old 06-26-2010, 07:02 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Code:
echo I\'d say: \"Go for it\!\"
 
1 members found this post helpful.
Old 06-26-2010, 07:05 AM   #3
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Original Poster
Rep: Reputation: 41
#*$!@*!
I don't know why I didn't just think of that... I kept thinking "quotations, backslash, quotations, backslash". 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.

Last edited by pr_deltoid; 06-26-2010 at 07:18 AM.
 
Old 06-26-2010, 12:01 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
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!"
 
Old 06-26-2010, 04:27 PM   #5
everToulouse
LQ Newbie
 
Registered: Apr 2010
Posts: 18

Rep: Reputation: 5
Code:
echo "I'd say: \"Go for it"'!'"\""
I'd say: "Go for it!"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Exclamation point in Grep for Negated Lookbehind: How to Do it? mattseanbachman Linux - Newbie 7 03-15-2010 09:45 PM
Bash escaping super_bash Linux - General 2 08-06-2009 01:04 PM
Bash - double quotes don't protect Exclamation marks geoff_f Programming 15 04-15-2007 10:10 PM
Exclamation point in disk path? (i.e. /dev/cciss!c0d0p3) jchrisos Fedora 0 07-18-2006 12:04 PM
how do you disable red exclamation point (up2date) in the gnome toolbar? harry349 Red Hat 3 05-26-2004 09:03 AM


All times are GMT -5. The time now is 12:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration