md5
Hello. When I do either of these commands at the prompt:
echo: =
echo: => filename
They appear to funcition with my expectation. The first returns the equal sign if I type <Enter>, and the second pipes the equal sign into "filename".
However, when I do something like this:
for %G in (=) do echo:%G>filename
No matter how many times I escape the equals sign, or not at all, it will not go into "filename". Any ideas on why that would not work? I have not found that problem to occur with any other characters tried so far. Thanks.
----------------------------
#2 30 Mar 2012 07:46
npocmaka
Shouldn't be:
for /F %G in ("=") do echo:%G>filename
the right command?
I think
for %G (something) do ...
(without command switch and quotes) will iterate through list of files in brackets
Last edited by npocmaka (30 Mar 2012 07:46)
----------------------------
#3 30 Mar 2012 07:53
md5
Hello.
Yes, my command was correct. For %G in (a b c) do echo:%G>filename. Try it yourself and see.
----------------------------
#5 31 Mar 2012 00:32
RG
As npocmaka stated...
Code: Select all
for /f %G in ("=") do echo.%G>filename.txt
Windows Shell Scripting and InstallShield
----------------------------
#6 31 Mar 2012 03:01
md5
My bad! He was quite right. If I only want to echo one character with the command, and if "=" is the character, then it works just as he stated. Yet, my objective, which I admit was not perfectly clarified, is to "echo" several characters separately while using only one command. I was using this command for my testing: for %G in (a b c) do echo:%G, which works perfectly in "most" cases. This would be the result:
a
b
c
Apparrently, it has some limitations in regard to which characters it allows, and, indeed, I can use the command again modified to the way he suggested. However, I cannot do it like this: for %G in (a b = c) do echo:%G in order to get the result I was hoping for:
a
b
=
c
The alternate method does not work: for /f %G in ("a b = c") do echo:%G, and I do not see how to change the options for "/f" to make it work in this way. Thanks for the suggestion anyway. It does allow me to work around the issue if need be.
----------------------------
#7 31 Mar 2012 03:35
RG
Could do it in a bat file like this... Does that help?
Code: Select all
@echo off
set filename=filename.txt
IF EXIST %filename% DEL /q %filename%
call :Echo1Char a b "=" c
goto :eof
:Echo1Char
for %%G in (%*) do echo.%%~G>>%filename%
goto :eof
Code: Select all
@echo off
for %%G in (%*) do echo.%%~G>>filename.txt
goto :eof
Echo1Char.bat a b "=" c
remembering to delete filename.txt when you want to start clean
Last edited by RG (31 Mar 2012 03:38)
Windows Shell Scripting and InstallShield
----------------------------
#8 31 Mar 2012 08:25
md5
Absolutely, that will work. Outstanding. It did not occur to me using that parameter extension in this case. But now that you have pointed me in the right direction, I found that this will work even a bit more efficiently, and in a batch or the command line:
for %G in (a b "=" c) do echo:%~G>>testing
Thanks again for the help.
----------------------------
#9 15 Apr 2012 19:14
dbenham
The token delimiters in a FOR IN() clause are the same as the token delimeters on the command line: <space> <tab> , ; =
I will ignore the <tab> because it doesn't play nice with my current console configuration
Code: Select all
>for %A in (a b,c;d=e) do @echo %A
a
b
c
d
e
Code: Select all
>for %A in (" " "," ";" "=") do @echo [%~A]
[ ]
[,]
[;]
[=]