zoukankan      html  css  js  c++  java
  • Shell script之if...then

    1  Variable in shell 

      If you want to print variable, then use echo command.

      In front of the variable to add $variabel or use ${variable} to fetch the value of variable.

    # echo $variable
    # echo $PATH

    2  if....then 

    if condition
    then
        condition is true
        execute all commands up to else statement
    else
        if condition is not true then
        execute all commands up to fi
    fi

    3  Example 

     1 #!/bin/bash
     2 # ----------------------------------------------------------------------------
     3 # call pythonscript, then modelsim
     4 # -----------------------------------------------------------------------------
     5 
     6 if [ $# -eq 0 ]; then
     7     here=$PWD;
     8     cd '../../02_modelsim'  # work directory in your project
     9     vsim -gui&
    10     cd $here;
    11 elif [ $1 == "-h" ]; then
    12     # questasim-doc: 
    13     evince /Software/AMS/current/questasim/v10.3b/docs/pdfdocs/_bk_questa_sim.pdf &
    14 fi

    4  Explanation

    `$` refer to `value of` and
    `#` refer to `number of / total number`

    So together

    `$#` refer to `The value of the total number of command line arguments passed.`

    Thus, you can use $# to check the number of arguments/parameters passed like you did and handle any unexpected situations.

    `$1` for `value of 1st argument passed`
    `$2` for 'value of 2nd argument passed`
  • 相关阅读:
    Spring Bean的作用域类型
    spring depends-on
    spring bean parent属性详解
    spring中autowire的用法
    Spring容器的属性配置详解的六个专题
    Spring bean注入方式
    Spring入门示例
    如何从官网下载Spring
    Hibernate 缓存
    [转]javascript Date format(js日期格式化)
  • 原文地址:https://www.cnblogs.com/mengdie/p/4366536.html
Copyright © 2011-2022 走看看