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> |
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>' Code:
$ fooBar="\!whatever" Anyway, hope this gets you going again. |
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 |
thanks guys ... it works with single quotes ... any way, i dont like this bash's behaviour :-(
|
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 |
The exclamation point is used for history expansion in an interactive shell.
Quote:
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>' You would want to use single quotes anyway because your string contains doublequotes. That way you don't have to escape them. |
All times are GMT -5. The time now is 09:07 AM. |