一 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·。

实例:

WindowsBatch与LinuxShell比较[变量值来自文件或命令]@echo off
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo get the value from one txt file
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
rem the num.txt file only contains one line "001".
WindowsBatch与LinuxShell比较[变量值来自文件或命令]

WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo work well
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set /p num=<num.txt
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %num%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo doesn't work
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set num=<num.txt
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %num%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
type num.txt | set num=
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %num%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
type num.txt | set /p num=
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %num%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set num=(`print num.txt`)
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %num%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo get value from command
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo some command work well, such as %time%, %dateWindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set bbb=%time
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %bbb%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set aaa=%date%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %aaa%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo general command doesn't work
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set ccc=('time /t')
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %ccc%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo one solution is to output the result to txt and then input it
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
time /> ddd.txt
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
set /p ddd=<ddd.txt
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo %ddd%
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo specially,in for clause, ('time /t') is as one command.
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
echo and if also use setlocal enabledelayedexpansion, the way also can implement get value from command.
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
setlocal enabledelayedexpansion
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
for /f %%i in ('time /t') do (
WindowsBatch与LinuxShell比较[变量值来自文件或命令]    
echo %%i
WindowsBatch与LinuxShell比较[变量值来自文件或命令]    
set ti=%%i
WindowsBatch与LinuxShell比较[变量值来自文件或命令]    
echo !ti!
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
)
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
pause

二 Linux Shell

1)超级简单,只需要使用·command parameters·。

 实例:

#!/bin/sh

ddd
=`cat ./ddd.txt`
echo $ddd

d
=`date`
echo $d

 

 完!

 

 


 

 

 

 

 

相关文章: