| Fedora This forum is for the discussion of the Fedora Project. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-28-2008, 10:56 AM
|
#1
|
|
Member
Registered: Jan 2007
Posts: 121
Rep:
|
escaping bash shell
hi guys,
i am trying to scape a "!" character in bash shell, but it looks having a bug in bash shell ...
the problem is a "!DOCTYPE" xml statement. When i try to asign a XML message to a variable, bash shell rejects the special character, when i scape the character (using \), bash shell accept it, BUT DO NOT clear that character from the message, which comes in a XML error.
i have fedora c6 an bas shell:
GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu)
am i doing something wrong ?
thanks in advance,
hector
<code>
[duque32@unknown-00-13-8f-c4-40-21 engine]$ msg="<?xml version=\"1.0\"?> <!DOCTYPE Employee SYSTEM \"/home/duque32/rouletteProjects/rouletteLibrariesInstallDir/kg_XMLLib/DTDs/Employee.dtd\"> <Employee> <Emp_Id>E-001 </Emp_Id> <Emp_Name>Vinod </Emp_Name> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>"
bash: !DOCTYPE: event not found
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$ msg="<?xml version=\"1.0\"?> <\!DOCTYPE Employee SYSTEM \"/home/duque32/rouletteProjects/rouletteLibrariesInstallDir/kg_XMLLib/DTDs/Employee.dtd\"> <Employee> <Emp_Id>E-001 </Emp_Id> <Emp_Name>Vinod </Emp_Name> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>"
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$ echo $msg
<?xml version="1.0"?> <\!DOCTYPE Employee SYSTEM "/home/duque32/rouletteProjects/rouletteLibrariesInstallDir/kg_XMLLib/DTDs/Employee.dtd"> <Employee> <Emp_Id>E-001 </Emp_Id> <Emp_Name>Vinod </Emp_Name> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>
SEE HERE, THE MESSAGE HAS THE SCAPE CHARACTER: <\!DOCTYPE
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$
[duque32@unknown-00-13-8f-c4-40-21 engine]$ bash -version
GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
[duque32@unknown-00-13-8f-c4-40-21 engine]$
</code>
|
|
|
|
02-28-2008, 11:26 AM
|
#2
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,703
|
Hi,
Do you need to use double quotes? It seems that single quotes solve your problem:
Code:
$ msg='<?xml version="1.0"?> <!DOCTYPE Employee SYSTEM "/home/Employee.dtd"> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>'
$ echo $msg
<?xml version="1.0"?> <!DOCTYPE Employee SYSTEM "/home/Employee.dtd"> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>
If the double quotes are needed you could also try using the eval command:
Code:
$ fooBar="\!whatever"
$
$ echo $fooBar
\!whatever
$
$ eval echo $fooBar
!whatever
$
It doesn't explains bash's behaviour. I do recall that I also encountered this on previous bash versions and don't think it is a bug.
Anyway, hope this gets you going again.
|
|
|
|
02-28-2008, 07:01 PM
|
#3
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,988
|
I'm not quite clear what you want : do you want to
1. escape it - which you seem to have done ok
2. ignore it - use single quotes as suggested, although you'd have to be careful using that var
3. remove it (!) - use sed
|
|
|
|
02-29-2008, 09:59 AM
|
#4
|
|
Member
Registered: Jan 2007
Posts: 121
Original Poster
Rep:
|
thanks guys ... it works with single quotes ... any way, i dont like this bash's behaviour :-(
|
|
|
|
03-15-2008, 05:50 AM
|
#5
|
|
Registered User
Registered: Mar 2008
Posts: 104
Rep:
|
Runnings these tests ...
$ my=! && echo $my
!
$ my='!' && echo $my
!
$ my="!" && echo $my
bash: !: event not found
... it looks like Bash is using '!' as a protected operator within double quotes only. Running additional tests in exactly this order ...
$ aha=1
$ my="!$aha" && echo $my
my="aha=1aha" && echo $my
aha=1aha
$ my="!aha" && echo $my
my="aha=1" && echo $my
aha=1
... it seems that '!' makes echoing the entire line where 'aha' was set. The user's .bash_history contains the echoed line, not the one with '!'.
There is some weird concept behind this (madness has a method), but I don't see any practical use for this right now.
Confused,
SIMP
Linux Archive
Last edited by simplicissimus; 04-02-2008 at 04:32 AM.
|
|
|
|
03-15-2008, 06:04 AM
|
#6
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
The exclamation point is used for history expansion in an interactive shell.
Quote:
|
Originally Posted by bash info manual
History expansions are introduced by the
appearance of the history expansion character, which is `!' by default.
Only `\' and `'' may be used to escape the history expansion character.
|
So you need to use single quotes in the assignment statement:
Code:
msg='<?xml version="1.0"?> <!DOCTYPE Employee SYSTEM "/home/duque32/rouletteProjects/rouletteLibrariesInstallDir/kg_XMLLib/DTDs/Employee.dtd"> <Employee> <Emp_Id>E-001 </Emp_Id> <Emp_Name>Vinod </Emp_Name> <Emp_E-mail>Vinod1@yahoo.com </Emp_E-mail> </Employee>'
Otherwise, bash is looking for a line in the history buffer starting with "DOCTYPE" to run.
You would want to use single quotes anyway because your string contains doublequotes. That way you don't have to escape them.
Last edited by jschiwal; 03-15-2008 at 06:06 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:09 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|