日期:2014-05-16  浏览次数:20644 次

WindowsBatch与LinuxShell比较[变量值来自文件或命令]

WindowsBatch与LinuxShell比较[变量值来自文件或命令]

?

?

一 Windows Batch

1) 如果变量的值来自文件,则必须类似set /p num=<num.txt 。
2)如果变量的值想来自命令的结果,则一些命令可以使用%%,例如set bbb=%time%,set aaa=%date%。对于一般的命令只能先输出到临时文件,然后再读入,例如time /t > ddd.txt set /p ddd=<ddd.txt。
3) 在for中可以使用命令,例如·time /t·。

实例:

复制代码
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
rem the num.txt file only contains one line "001".
echo work well
echo %num%
echo doesn't work
echo %num%
echo %num%
echo %num%
echo %num%
echo get value from command

echo %bbb%
echo %aaa%
echo general command doesn't work
echo %ccc%
echo one solution is to output the result to txt and then input it
set/p ddd=<ddd.txt
echo %ddd%
echo special