#!/usr/bin/sh clspath="bootstrap.jar" for k in *.jar do clspath=$clspath:$PWD/$k echo "current jar is $k." done printf"classpath is %s"$clspath
工作的很好,于是在windows同样try了一下batch
@echo off
set clspath=bootstrap.jar for%%j in (*.jar) do ( set clspath=%clspath%;%cd%\%%j echo current jar is %%j. ) echo classpath is %clspath%
很奇怪的是最后的结果却是 classpath is bootstrap.jar;D:\workflow\bingo\lib\servlet-api.jar。很显然batch默认不支持变量迭代更改。 google了一下,发现原因,稍微改一下:
1@echo off 2 3set clspath=bootstrap.jar 4setlocal enabledelayedexpansion 5for%%j in (*.jar) do ( 6set clspath=!clspath!;%cd%\%%j 7echo current jar is %%j. 8) 9echo classpath is %clspath% 10endlocal