zoukankan      html  css  js  c++  java
  • Shell 变量

    1. 定义变量

    1. 变量名和等号之间不能有空格
    2. 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头。

      除了显式地直接赋值,还可以用语句给变量赋值,如:

    1 for file in `ls /etc`
    2 
    3 file in $(ls /etc)

    2. 使用变量

    1 your_name="qinjx"
    2 echo $your_name
    3 echo ${your_name}


      使用变量时加上$即可,{}是为了确定变量名的边界,推荐使用{}

    3. 只读变量

      使用 readonly 命令可以将变量定义为只读变量,只读变量的值不能被改变。

    1 name="virgosnail"
    2 readonly name

    4. 删除变量

      使用 unset 命令可以删除变量.
      变量被删除后不能再次使用。unset 命令不能删除只读变量。

    1 unset name

    5. 字符串

    5.1 直接赋值

      字符串值中间不能有空格,反引号(··),单引号(‘’),双引号(“”)这三种符号不会输出,其他字符原样输出。

    5.2 单引号 ' '

      字符串值可以空格,所有字符原样输出。

    5.3 双引号 " "

      字符串可以空格,可以使用转义字符。可以使用变量

    5.4 反引号 ``

      命令替换,执行命令时,先执行 `` 里面的命令执行,把执行的结果加入到原来的命令里面,然后执行原来的命令。

  • 相关阅读:
    WINFORM 設計時 未能加载文件或程序集問題解決
    Remove row from generic datatable in C#(The given DataRow is not in the current DataRowCollection)
    questa.sim in the linux
    the io_printf
    how to search new file in linux
    the rld control core
    window's chkdsk
    tq
    the init state machine
    brazen out
  • 原文地址:https://www.cnblogs.com/virgosnail/p/9959383.html
Copyright © 2011-2022 走看看