Page 1 of 1

How can I echo Bla"la (containing one quote) in a text file?

Posted: 23 Jul 2010 08:03
by Andi
Hi
I am shell scripting in Windows Server 2003/xp.
A user of my script could set a path into the variable am_path wrongly.
For example

Code: Select all

set am_path=some"wrongPathwithQuotes

So I need to check what he set later from within the script.
In order to do that I need to put the contents of am_path into a text file for find does not work in a search containing quotes to begin with and findstr also needs a text file.
However, echoing variable contents into a text file only works if that variable contains an even number of quotes.
This will not work for example with am_path as set above but will rather echo on the console:

Code: Select all

echo %am_path%>c:\tmp\path2BeChecked.txt


Would somebody know how I could put the contents of a variable that contains an uneven number of quotes into a text file?

Thank you.
Andreas

Re: How can I echo Bla"la (containing one quote) in a text f

Posted: 23 Jul 2010 08:48
by aGerman
Andi wrote:In order to do that I need to put the contents of am_path into a text file for find does not work in a search containing quotes to begin with and findstr also needs a text file.

This isn't true. You could pipe e.g. an echo output directly to FIND or FINDSTR using the | sign.


Andi wrote:However, echoing variable contents into a text file only works if that variable contains an even number of quotes.
This will not work for example with am_path as set above but will rather echo on the console:

Code: Select all

echo %am_path%>c:\tmp\path2BeChecked.txt


Would somebody know how I could put the contents of a variable that contains an uneven number of quotes into a text file?

Write the line in an opposite style.

Code: Select all

>c:\tmp\path2BeChecked.txt echo %am_path%


Regards
aGerman

Re: How can I echo Bla"la (containing one quote) in a text f

Posted: 26 Jul 2010 00:46
by Andi
Hi aGerman,

thanx a lot, that was exactly the information I was missing.

Sincerely