J
jihadmhaddad
Hi
I have delayed expansion set, which also means I can reference my
variables using exclamation marks (!var!) instead of percent (%var%).
However I have a problem assigning the special character
'!' (exclamation mark) to a list. Here is what happens. I want to make
a list containing string elements which contain exclamation marks, and
then I want to loop through that list.
The following code almost does what I need:
----------------------
@echo off
set list=( "elem1^!1" "elem2^!2" "elem4^!4" "elem3^!3" )
echo List using exclamation is !list!
echo List using percent is %list%
for %%i in !list! do (
echo %%i
)
----------------------
This gives the following output with error
----------------------
List using exclamation is ( "elem1!1" "elem2!2" "elem4!4" "elem3!3" )
List using percent is ( "elem12" "elem43" )
!list! was unexpected at this time.
----------------------
How do I reference my list so that I can loop through it?
I cannot use %list%, since this gives a wrong list, as can be seen in
the echo line "using percent".
I have all this trouble because I am using delayed expansion. I tried
turning it off for the example, and all went well using %%
I would appreciate any help I can get.
Jeeji
I have delayed expansion set, which also means I can reference my
variables using exclamation marks (!var!) instead of percent (%var%).
However I have a problem assigning the special character
'!' (exclamation mark) to a list. Here is what happens. I want to make
a list containing string elements which contain exclamation marks, and
then I want to loop through that list.
The following code almost does what I need:
----------------------
@echo off
set list=( "elem1^!1" "elem2^!2" "elem4^!4" "elem3^!3" )
echo List using exclamation is !list!
echo List using percent is %list%
for %%i in !list! do (
echo %%i
)
----------------------
This gives the following output with error
----------------------
List using exclamation is ( "elem1!1" "elem2!2" "elem4!4" "elem3!3" )
List using percent is ( "elem12" "elem43" )
!list! was unexpected at this time.
----------------------
How do I reference my list so that I can loop through it?
I cannot use %list%, since this gives a wrong list, as can be seen in
the echo line "using percent".
I have all this trouble because I am using delayed expansion. I tried
turning it off for the example, and all went well using %%
I would appreciate any help I can get.
Jeeji