WindowsBatch与LinuxShell比较[变量值来自文件或命令]
WindowsBatch与LinuxShell比较[变量值来自文件或命令]
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
@echooff![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo get the value from one txt file
rem the num.txt file only contains one line "001".![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo work well
set/p num=<num.txt
echo %num%![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo doesn't work
set num=<num.txt
echo %num%
type num.txt | set num=
echo %num%
type num.txt | set/p num=
echo %num%
set num=(`print num.txt`)
echo %num%![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo get value from command
echo some command work well, such as %time%, %date% ![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441337.gif)
set bbb=%time%
echo %bbb%
set aaa=%date%
echo %aaa%![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo general command doesn't work
set ccc=('time/t')
echo %ccc%![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo one solution is to output the result to txt and then input it
time/t > ddd.txt
set/p ddd=<ddd.txt
echo %ddd%![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
echo specially,in for clause,('time/t') is as one command.
echo and if also usesetlocal enabledelayedexpansion, the way also can implement get value from command.
setlocal enabledelayedexpansion
for/f %%i in ('time/t')do(
echo %%i
set ti=%%i
echo !ti!
)![WindowsBatch与LinuxShell比较[变量值来源于文件或命令]](http://img.reader8.net/uploadfile/jiaocheng/20140168/2956/2014012900562441336.gif)
pause二 Linux Shell
1)超级简单,只需要使用·command parameters·。
实例:
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#!/bin/sh?
完!