• shell--shell是什么?


    shell作为linux的使用者来说,是对linux系统使用的必须工具。

    学好shell的基础

    1. vim编辑器的使用
    2. 能够熟练使用linux并且命令积累要广泛
    3. 熟练掌握linux正则表达式及四大神器:grep,sed,awk,find
    4. 熟练常用的服务

    shell脚本简介:

    1.什么是shell?

    在计算机科学中,Shell俗称壳(用来区别于核),是指“提供使用者使用界面”的软件(命令解析器)。它接收用户命令,然后调用相应的应用程序。

    2.什么是shell脚本?

    由linux命令,变量和流程控制语句等结合起来的工具

    #查看系统支持的shell
    [root@test ~]# cat /etc/shells
    /bin/sh
    /bin/bash
    /sbin/nologin
    /usr/bin/sh
    /usr/bin/bash
    /usr/sbin/nologin

    shell脚本的建立和执行的规范

    1. 脚本的名称和目录分类放整齐
    2.  文件结尾使用.sh结构
    3.  脚本第一行指定好命令解释器格式为:
    4. 做好注释,方便检查
    5. 以缩进的方式做整齐

    执行脚本的方法:

    sh和source的区别

        sh测试如下:

    [root@test scripts]# vim test_sh.sh
    #!/bin/bash
    sh="this is sh"
    echo $sh
                                               
    [root@test scripts]# sh test_sh.sh 
    this is sh
    [root@test scripts]# echo $sh

        source测试如下:

    [root@test scripts]# vim test_source.sh
    #!/bin/bash
    so='this is source'
    echo $so
                                          
    [root@test scripts]# source test_source.sh
    this is source
    [root@test scripts]# echo $so
    this is source

    可以看出source执行完成后会将脚本中的变量生效在命令行中

    .和./ 的区别

    测试之前先清除之前的变量影响用之前的sh测试./用source测试.执行

    #清除so的影响
    [root@test scripts]# unset so
    [root@test scripts]# echo $so
    
    [root@test scripts]# 
    ##使用该方法需要文件有执行权限 
    [root@test scripts]# chmod +x test_sh.sh test_source.sh 
    [root@test scripts]# ll test_sh.sh test_source.sh
    -rwxr-xr-x 1 root root 37 12月  2 19:22 test_sh.sh
    -rwxr-xr-x 1 root root 41 12月  2 19:24 test_source.sh
    ##使用./也就是路径执行
    [root@test scripts]# ./test_sh.sh 
    this is sh
    、
    [root@test scripts]# echo $sh
    
    ##使用.执行
    [root@test scripts]# . test_source.sh 
    this is source
    [root@test scripts]# echo $so
    this is source

    可以看出使用路径直接执行该脚本效果等同于sh使用.效果等同于source

    •  sh    执行时会创建一个新的shell环境
    • source  会在当前shell环境中执行

     

     

  • 相关阅读:
    mmap文件修改内容的写回
    信号处理之物理信号和软件信号
    从printXX看tty设备(5)串口终端
    从printXX看tty设备(3)键盘输入处理
    LeetCode——Hamming Distance
    LeetCode——Add Strings
    计算树的高度和节点的个数
    LeetCode——Diameter of Binary Tree
    LeetCode——Number of Boomerangs
    九大排序算法总结
  • 原文地址:https://www.cnblogs.com/ExzaiTin/p/7955343.html
Copyright © 2020-2023  润新知