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·。
实例:
@echooff
echo get the value from one txt file
rem the num.txt file only contains one line "001".
echo work well
set/p num=<num.txt
echo %num%
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%
echo get value from command
echo some command work well, such as %time%, %date%
set bbb=%time%
echo %bbb%
set aaa=%date%
echo %aaa%
echo general command doesn't work
set ccc=('time/t')
echo %ccc%
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%
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!
)
pause
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->echo get the value from one txt file
rem the num.txt file only contains one line "001".
echo work well
set/p num=<num.txt
echo %num%
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%
echo get value from command
echo some command work well, such as %time%, %date%
set bbb=%time%
echo %bbb%
set aaa=%date%
echo %aaa%
echo general command doesn't work
set ccc=('time/t')
echo %ccc%
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%
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!
)
pause
二 Linux Shell
1)超级简单,只需要使用·command parameters·。
实例:
#!/bin/sh
ddd=`cat ./ddd.txt`
echo$ddd
d=`date`
echo$d
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->ddd=`cat ./ddd.txt`
echo$ddd
d=`date`
echo$d
完!
相关推荐
linux shell命令tr的用法
LINUX SHELL命令练习 题
linux shell命令sed的使用方法
最牛B的 Linux Shell 命令,最牛B的 Linux Shell 命令,
简单的说shell程序就是一个包含若干行shell或者linux命令的文件,象编写高级语言的程序一样,编写一个shell程序需要一个文本编辑器.如Ⅵ等.在文本编辑环境下,依据shell的语法规则,输入一些shell/linux命令行,形成...
linux超级基础系列——shell变量(本地变量和环境变量 linux超级基础系列——shell变量(本地变量和环境变量
Linux 系统 shell脚本读取配置文件
linux shell命令 有利于学习研究
linux,shell的常用命令,课件很不错总结很详细
linux命令大全介绍了linux shell的一些常用命令
Linux shell 及常用命令介绍.txt 1、更改帐号密码 语法:passwd Old password: <输入旧密码> New password: <输入新密码〉 Retype new password: <再输入一次密码> 2、联机帮助 语法: man 命令 例如: man ls 3、...
linuxshell命令 unixshell命令教程
实现了十多个Linux shell命令,能够在Linux环境下运行和检测
Linuxshell大作业.pdf
实战Linux Shell编程与服务器管理的脚本文件和数据文件
主要介绍了python文件读写操作与linux shell变量命令交互执行的方法,涉及对文件操作及Linux shell交互的技巧,需要的朋友可以参考下
包含linuxshell命令unixshell命令教程的pdf的文件
第一节 Linux系统概述 一、Linux简介 二、Linux系统的特点 三、Linux系统的组成 第二节 Linux系统的使用 ...三、Shell的测试命令 四、条件语句 五、循环语句 六、函数 七、参数变量和内部变量
文件包含大作业shell脚本(快速备份系统)源码,实验课做的Linux实验shell脚本:Samba实验,DDNS(DHCP服务器 和DNS服务器的配置)的shell脚本,运行脚本每个实验只需要两三分钟即可完成。 其中sy1为实验一脚本,sy2...
Linux常用命令 2 1.1 su用户切换 2 1.2 useradd 添加用户 2 1.3 passwd修改口令 2 1.4 ls查看文件/目录 3 1.5 cd改变工作目录 4 1.6 pwd显示工作目录 4 1.7 mkdir创建目录 5 1.8 rmdir删除空目录 5 1.9 cp文件/目录...