[英]Convert unix to windows shell script
I'm trying to convert the following unix shell script to windows: 我正在尝试将以下unix shell脚本转换为Windows:
for strWorkerDirectory in $BASEDIR/worker01/applogs $BASEDIR/worker01/filtered $BASEDIR/worker01/filtered/error-logs $BASEDIR/worker01/filtered/logs $BASEDIR/worker01/filtered/session-logs
do
if [ ! -d $strWorkerDirectory ]; then
mkdir -p $strWorkerDirectory
fi
done
So far, I came up with this: 到目前为止,我想到了这个:
FOR %%strWorkerDirectory IN (%BASEDIR%worker01\applogs %BASEDIR%worker01\filtered %BASEDIR%worker01\filtered\error-logs %BASEDIR%worker01\filtered\logs %BASEDIR%worker01\filtered\session-logs) DO
(
IF exist %%strWorkerDirectory ( echo %%strWorkerDirectory exists ) ELSE ( mkdir %%strWorkerDirectory && echo %%strWorkerDirectory created)
)
but i'm getting an error message which just says something is wrong here 但我收到一条错误消息,提示此处有问题
"%strWorkerDirectory" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
What would be the correct conversion here? 什么是正确的转换?
Two issues: 两个问题:
%%s
for example. 例如,尝试仅使用%%s
。 Note that depending on the type of the FOR
loop the names have a meaning (see FOR /?
for more information); 注意,根据FOR
循环的类型,名称具有含义(有关更多信息,请参见FOR /?
)。 for example when used with `FOR /F "tokens=..."``. 例如,当与`FOR / F“ tokens = ...”``一起使用时。 In your case it shouldn't matter though. 对于您而言,这没关系。 DO
开括号必须与DO
在同一行 Complete example: 完整的例子:
FOR %%s IN (%BASEDIR%worker01\applogs %BASEDIR%worker01\filtered %BASEDIR%worker01\filtered\error-logs %BASEDIR%worker01\filtered\logs %BASEDIR%worker01\filtered\session-logs) DO (
IF exist %%s ( echo %%s exists ) ELSE ( echo mkdir %%s && echo %%s created)
)
Hint: you can use a caret ( ^
) as line continuation character to avoid overly long lines. 提示:可以使用脱字符号( ^
)作为换行符,以免线条过长。 Just make sure there is really no other character (not even whitespace) after the caret. 只要确保插入符号后确实没有其他字符(甚至没有空格)即可。
FOR %%s IN (%BASEDIR%worker01\applogs ^
%BASEDIR%worker01\filtered ^
%BASEDIR%worker01\filtered\error-logs ^
%BASEDIR%worker01\filtered\logs ^
%BASEDIR%worker01\filtered\session-logs) DO (
IF exist %%s ( echo %%s exists ) ELSE ( echo mkdir %%s && echo %%s created)
)
EDIT As commenter @dbenham points out, the line continuation inside above are not actually neccessary. 编辑正如评论者@dbenham指出的那样,上面的行连续实际上不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.