zoukankan      html  css  js  c++  java
  • 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·。

    实例:

    @echo off

    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 /> ddd.txt
    set /p ddd=<ddd.txt
    echo %ddd%

    echo specially,in for clause, ('time /t') is as one command.
    echo and if also use setlocal 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

     完!


     


    作者:iTech
    微信公众号: cicdops
    出处:http://itech.cnblogs.com/
    github:https://github.com/cicdops/cicdops

  • 相关阅读:
    ubuntu下手动安装autoconf
    解决VMware下的ubuntu桌面鼠标键盘失效的问题
    DP搬运工1
    把数字转换成货币格式
    指定字符隐藏
    JS 时间获取 (常用)
    electron 安装
    el-form表单校验包含循环
    算法-07| 动态规划
    纯手撸——归并排序
  • 原文地址:https://www.cnblogs.com/itech/p/1590671.html
Copyright © 2011-2022 走看看