2

I'm trying to translate a .bat file into a .sh script. Several parameters are passed to the script, one of these being a hash table. The code looks like...

date /T
time /T

FOR /F "tokens=1-11" %%A IN (%4) DO (
   set args1=%%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K
)
FOR /F "tokens=12" %%A IN ("%4") DO (
   set args2=%%A
)
FOR /F "tokens=12*" %%A IN (%4) DO (
   set dummy=%%A
   set args3=%%B
)

I'm not sure what is going on here, or how to handle it? Any suggestions? Or good reference pages online I can take at look at?

user1795370
  • 332
  • 2
  • 4
  • 18

1 Answers1

2

Here is a good reference page: http://technet.microsoft.com/en-us/library/bb490909.aspx

Breakdown

The first loop is treating the input as a filenameset.

  • This is storing the first 11 whitespace delimited items in the variable args1.

The second loop is treating the input as a literal string.

  • This is storing just the 12 whitespace delimited item in the variable args2.

The last loop is treating the input as a filenameset.

  • This is storing all the remaining whitespace delimited items after the 12th item in the variable args3.

Example

I would recommend adding the echo command after each loop so you can see what the parsed values look like.

FOR /F "tokens=1-11" %%A IN (%4) DO (
   set args1=%%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K
)
echo %args1%
FOR /F "tokens=12" %%A IN ("%4") DO (
    set args2=%%A
)
echo %args2%
FOR /F "tokens=12,*" %%A IN (%4) DO (
   set args3=%%B
)
echo %args3%
Community
  • 1
  • 1
David Ruhmann
  • 11,064
  • 4
  • 37
  • 47