shell 编程

shell 编程

变量赋值

  • 变量和赋值之间用=连接,不能有空格

  • shell编程认赋值都是字符串,所以单引号 双引号 或者直接字符串都一样

    [root@127 download]# name=test
    [root@127 download]# name1="test1"
    [root@127 download]# name2='test2'
    [root@127 download]# echo $name1
    test1
    [root@127 download]# echo $name2
    test2
    [root@127 download]# echo $name
    test
    [root@127 download]#
    
    
  • 单引号变量,不识别特殊语法,双引号变量,可以识别特殊语法,反引号中的命令结果会被保留下来

    [root@127 download]# name=test
    [root@127 download]# name1="test1"
    [root@127 download]# name2='test2'
    # 双引号可以识别$变量名的用法,单引号不行
    [root@127 download]# echo "$name1"
    test1
    [root@127 download]# echo "$name"
    test
    [root@127 download]# echo "$name2"
    test2
    [root@127 download]# echo '$name2'
    $name2
    [root@127 download]# echo '$name1'
    $name1
    [root@127 download]# echo '$name'
    $name
    # 反引号
    [root@127 download]# test=`ls -ll`
    [root@127 download]# echo $test
    total 82644 drwxr-xr-x 17 501 501 4096 Mar 11 15:52 Python-3.6.12 -rw-r--r-- 1 root root 84623360 Aug 15 2020 Python-3.6.12.tar
    
    

环境变量设置

环境变量一般指用export内置命令导出的变量,用于定义shell的运行环境

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本