• #一个简单的脚本#


    概念

    脚本简单地说就是一条条的文字命令,这些文字命令是可以看到的(如可以用记事本打开查看、编辑),脚本程序在执行时,是由系统的一个解释器,将其一条条的翻译成机器可识别的指令,并按程序顺序执行。因为脚本在执行时多了一道翻译的过程,所以它比二进制程序执行效率要稍低一些。

    一个简单的脚本

    Hi@DESKTOP-ONU36VQ MINGW64 ~
    $ mkdir ~/local
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~
    $ cd ~/local
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ touch demo.txt
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start demo.txt
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ cd ~/Desktop
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ sh ~/local/demo.txt
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ cd ~/local; pwd
    /c/Users/Hi/local
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ touch ~/.bashrc
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start ~/.bashrc
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ source ~/.bashrc
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ mv ~/local/demo.txt ~/local/demo
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start demo
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ cd ~/Desktop
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ demo yyy
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ cd ~/local/demo
    bash: cd: /c/Users/Hi/local/demo: Not a directory
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ cd ~/local
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start demo
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ cd ~/Desktop
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ demo ttt

    解释

    ###### *//创建一个local文件(在Hi里面-这是我的电脑的默认文件名)*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~
    $ mkdir ~/local
    
    ###### *//进入local文件*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~
    $ cd ~/local
    
    ###### *//创建一个demo文本文档*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ touch demo.txt
    
    ------
    
    ###### *//开始在demo文本文档里面编写内容*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start demo.txt
    
    ###### (*demo.txt里面的内容:)*
    
    mkdir $1 
    cd $1
    mkdir css js
    touch index.html css/style.css js/main.js
    exit
    
    ------
    
    ###### *测试*--在桌面创建一个demo
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ cd ~/Desktop
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ sh ~/local/demo.txt
    
    ------
    
    ###### *将 ~/local 添加到 PATH 里*
    
    ###### *复制路径备用*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ cd ~/local; pwd
    /c/Users/Hi/local
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ touch ~/.bashrc
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ start ~/.bashrc
    
    export PATH="local的绝对路径:$PATH"
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ source ~/.bashrc
    
    ------
    
    ###### *将dome.txt的后缀删掉*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/local
    $ mv ~/local/demo.txt ~/local/demo
    
    ------
    
    ###### *测试*
    
    Hi@DESKTOP-ONU36VQ MINGW64 ~/Desktop
    $ demo yyy
  • 相关阅读:
    hash介绍
    序列化
    面向对象编程
    计算机系统基础知识05
    19、Python之队列
    18、Python之多线程
    17、Python之paramikomo
    16、Python之socket网络编程
    15、Python之异常处理
    14、Python之反射
  • 原文地址:https://www.cnblogs.com/BUBU-Sourire/p/11027246.html
Copyright © 2020-2023  润新知