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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Andi
Posts: 5
Joined: 23 Jul 2010 07:46

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

#1 Post by Andi » 23 Jul 2010 08:03

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 23 Jul 2010 08:48

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

Andi
Posts: 5
Joined: 23 Jul 2010 07:46

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

#3 Post by Andi » 26 Jul 2010 00:46

Hi aGerman,

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

Sincerely

Post Reply