For example;
Code: Select all
@echo off
set x=1
set test=Hello
if %x% equ 1 (
set test=Hi
set test=%test% There
)
echo %test%
If I change it to;
Code: Select all
@echo off
set x=2
set test=Hello
call if %x% equ 1 (
set test=Hi
set test=%test% There
)
echo %test%
to make it work reliably, I have to use;
Code: Select all
@echo off
set x=2
set test=Hello
if %x% equ 1 (
set test=Hi
)
if %x% equ 1 (
set test=%test% There
)
echo %test%
For the curious: I was making a script to number sets of files and I wanted it to pad the counter with leading zeroes if there were more than nine files in a set. So I had it count them and set a flag if there were more than nine files. Then if that flag was set, it would add a zero to the start of the variable and then truncate it to the last two characters, giving me a two-digit counter. As above, this didn't work unless I used two separate comparisons.