zoukankan      html  css  js  c++  java
  • linux shell 脚本

    Shell notes

    鸟哥的私房菜 第13章

    l  编写一个shell脚本,需要用”#!/bin/bash”开头:

    #!/bin/bash

    # Program:

    #      “这里输入此脚本的功能描述”

    # History:

    # “输入日期”  “输入作者” “输入版本”

    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

    export PATH

    read –p “Please input your first name: “ firstname  # 提示用户输入

    read –p “Please input your last name: “ lastname  # 提示用户输入

    echo –e “ Your full name is: $firstname $lastname” #结果由屏幕输出

    l  编写一个shell脚本,创建3个以你输入的字符串开头,并以日期结尾的文件。

    #!/bin/bash

    # Program:

    #      “创建3个以你输入的字符串开头,并以日期结尾的文件。”

    # History:

    # “20171226” “Hongbo” “first release”

    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

    export PATH

    # 让用户输入文件名,并取得fileusr这个变量

    echo –e “I will use ‘touch’ command to create 3 files.”

    read –p “Please input your filename: “ fileuser

    # 为了避免用户随意按[Enter],利用变量功能分析文件名是否有设置

    filename=${fileuser:-“filename”}

    # 开始利用date命令来取得所需要的文件名了

    date1=$(date --date=’2 days ago’ +%Y%m%d)

    date2=$(date --date=’1 days ago’ +%Y%m%d)

    date3=$(date +%Y%m%d)

    file1=${filename}${date1}

    file1=${filename}${date2}

    file1=${filename}${date3}

    # 创建文件名

    touch “$file1”

    touch “$file2”

    touch “$file2”

    l  编写一个脚本,进行简单的加减乘除

    #!/bin/bash

    # Program:

    #      “创建3个以你输入的字符串开头,并以日期结尾的文件。”

    # History:

    # “20171226” “Hongbo” “first release”

    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

    export PATH

    echo –e “You SHOULD input 2 numbers, I will cross them! ”

    read –p “first number: “ firstnu

    read –p “second number: “ secnu

    total=$(($firstnu*$secnu))

    echo –e “ The result of $firstnu x $secnu is ==> $total”

    l  Script 的执行方式区别 (3种执行脚本的方式:sh ;source;直接)

    sh sh02.sh 和 ./sh02.sh 都是在让sh02.sh在一个新开的子进程bash中执行脚本,脚本执行过程中产生的变量,在脚本执行结束后,就不存在了。

    而source sh02.sh在脚本执行过程中产生的变量,会在执行结束后依然存在于bash中

    l  条件判断

    if [条件]; then

           执行语句

    fi

  • 相关阅读:
    Ubuntu 安装第三方工具
    mysql 安装
    启动springboot的项目的时候报错 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    idea激活码 2020年12月17日 可以用到 2021年2月10号
    logback-spring.xml相关配置的注释
    Exception in thread "main" java.lang.UnsupportedOperationException 数组转化为list后,返回的List是具有固定长度的私有静态内部类
    一.设计模式之六大原则
    redis经典面试题
    windows远程连接linux服务器的redis 连接不上
    linux下安装mysql 8.* MySQL连接时找不到mysql.sock文件
  • 原文地址:https://www.cnblogs.com/HITSZ/p/8117789.html
Copyright © 2011-2022 走看看