Display the content of a variable in batch
valarno
-
dubcek Posted messages 18702 Registration date Status Contributeur Last intervention -
dubcek Posted messages 18702 Registration date Status Contributeur Last intervention -
Hello,
I can't display the content of a variable in a DOS batch.
Here is my batch (the goal is to display the variable "fic" at each iteration of the loop)
for /f %%a in ('dir /b') do (
set fic=%%a
echo "%fic%"
)
I've tried: echo %%fic, echo %fic%, with quotes, without quotes, nothing works!!
If anyone sees the error, I'm open to suggestions!
Thanks in advance
I can't display the content of a variable in a DOS batch.
Here is my batch (the goal is to display the variable "fic" at each iteration of the loop)
for /f %%a in ('dir /b') do (
set fic=%%a
echo "%fic%"
)
I've tried: echo %%fic, echo %fic%, with quotes, without quotes, nothing works!!
If anyone sees the error, I'm open to suggestions!
Thanks in advance
Configuration: Windows XP Firefox 3.0.6
5 réponses
In fact, the problem isn't the assignment of a value to the variable fic (with or without space it does indeed get a value). The problem is on the echo line.
What does the echo line return to you?
Because I've always seen that you MUST put spaces in BATCH.
--
Pico ;)
Because I've always seen that you MUST put spaces in BATCH.
--
Pico ;)
Here is the batch execution process. As you can see, `fic` receives a different value in each iteration (I made sure to include a space for `set fic = %%a`), but `echo` always returns the same value that corresponds to nothing... and especially not to the value of `fic`!!
W:\>for /F %a in ('dir /b') do (
set fic = %a
echo ~DF9DCF.tmp
)
W:\>(
set fic = ARC1C9
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = EScan
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = ExchangePerflog_8484fa312d2606bae8e1270f.dat
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = fichier2.txt
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = hsperfdata_ARMES
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = java_install_reg.log
echo ~DF9DCF.tmp
)
W:\>for /F %a in ('dir /b') do (
set fic = %a
echo ~DF9DCF.tmp
)
W:\>(
set fic = ARC1C9
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = EScan
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = ExchangePerflog_8484fa312d2606bae8e1270f.dat
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = fichier2.txt
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = hsperfdata_ARMES
echo ~DF9DCF.tmp
)
~DF9DCF.tmp
W:\>(
set fic = java_install_reg.log
echo ~DF9DCF.tmp
)