如何将 Unix 外壳脚本修改为 Windows 批处理文件?



我需要转换以下Unix脚本以在Windows上运行。我假设cd命令将更改为调用direcho命令将更改为调用print

该脚本检查给定文件的目录,如果该文件不存在,则脚本循环/休眠,然后再次检查。

我主要是在努力如何最好地转换变量和循环命令,任何提示/提示将不胜感激?

cd $DIRECTORY_NAME
echo "You are currently in $(pwd) directory"
numfiles=0
while [ $numfiles -lt "1" ]
do
export filename=`ls SWIX_BAU_success`
export numfiles=$(echo $filename | wc -w)
echo "$numfiles file found"
if [ $numfiles -ge "1" ]
then
echo "$filename file found"
exit 0
else
echo "Incorrect number of files found, 1 file expected"
numfiles=0
sleep 300
fi
done

当您撤销该问题时,我只是要在SO上发布此答案。
假设SWIX_BAU_success是一个只有一个文件的(子(目录。

@Echo off
cd /D "%DIRECTORY_NAME%"
echo You are currently in directory: %CD%
Set numfiles=0
For /f "tokens=1,* delims=:" %%A in (
'Dir /B "SWIX_BAU_success" ^| findstr /n ^ '
) DO Set numfiles=%%a&Set filename=%%B
If %numfiles% equ 1 (
echo %filename% found
exit /B 0
) else (
echo "Incorrect number of files found, 1 file expected"
set numfiles=0
Timeout /T 300
)

最新更新