I am using a for loop and constructing names of env variables ( like abc%%i , where i is the loop variable ) that are to be read , and use delayed expansion to print out their values (assuming these env variables have already been set ) ..
echo is dos provides the facility to mention the field width of the variable to be printed out like echo %x:~-8% will right justify the value of x and the field width will be 8 ..
But since i am using delayed expansion , !abc%%i:~-8! does not seem to be working .
Any ideas as to how to set field width while using delayed expansion ,??
Happiness
Deepak
I don’t know who told you that
%x:~-8%would pad out your variable but they’re wrong, at least in the version ofcmdthat I’m using (XP).That construct will simply give tou the last 8 characters if the variable is 8 or more. If it’s less than 8, you’ll get the variable itself, sans padding.
If you want it padded, you can use something like:
And, as can be seen from this script,
!abc%%i:~-8!works just fine once you realise that you’re responsible for the padding:This outputs:
as you would expect.