zoukankan      html  css  js  c++  java
  • shell随笔 风行天下

    一,

    case的详细用法:   参考文章(http://blog.csdn.net/dreamtdp/article/details/8048720)

      语句实例:由用户从键盘输入一个字符,并判断该字符是否为字母、数字或者其他字符,并输出相应的提示信息。

    #!/bin/bash
    read -p "press some key ,then press return :" KEY
    case $KEY in
    [a-z]|[A-Z])
    echo "It's a letter."
    ;;
    [0-9]) 
    echo "It's a digit."
    ;;
    *)
    echo "It's function keys、Spacebar or other ksys."
    esac

      二,

    aix 中shell 的read用法: 参考文章:(http://www.kuqin.com/aixcmds/aixcmds4/read.htm)

    实例读取一行,把它分成字段,并使用 "Please enter: " 作为提示符,请输入:

    read word1?"Please enter: " word2

    系统显示:

    Please enter:

    You enter:
    hello world

    变量 word1 的值应该是 "hello",变量 word2 应该是 "world."

    三,函数的用法

    参考文章:(http://c.biancheng.net/cpp/view/7011.html)

    先来看一个例子:

    #!/bin/bash
    
    # Define your function here
    Hello () {
       echo "Url is http://see.xidian.edu.cn/cpp/shell/"
    }
    
    # Invoke your function
    Hello

    运行结果:

    $./test.sh
    Hello World
    $
    另外还可以函数套函数使用

    四,多级菜单的例子 (http://m.bubuko.com/infodetail-1210960.html)
    自己的测试例子:

    测试例子:

    输入1-6打印文字,输入q退出,输入其它继续让用户输入

    While true

    do

    read sq?”please input a number::”

    case $sq in

         [1-3]) echo “the first mode”

            ;;

         [4-6]) echo “the second mode~~~~”

            ;;

     q)

              echo “exiting……..”

               sleep 1

               exit 0

               ;;

    *) echo “finally!!!~~~~”

         Continue

         ;;

    esac

    done

    +++++++++++++++++++++++++++++++++++++++++++++

    五,AIX系统中输入topas等待4秒钟然后停止退出

    topas <<EOF

    sleep 4

    q

    EOF

     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    expect交互式命令的用法

    使用spawn出现找不到spawn命令:需要添加执行权限

    1. [root@svr5 ~]# chmod +x expect_ssh.sh

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  • 相关阅读:
    Python正则表达式(3)--字符串匹配开头结尾
    Python正则表达式(2)---字符串匹配多个字符
    Python正则表达式(1) --匹配单个字符
    Navicate Premium 永久破解
    升级pip指令
    爬虫(自学)之User Agent 第三方库my_fake_useragent 和 fake_useragent
    django drf 反序列化上传图片
    git的使用
    python 爬虫 基本库使用urllib之urlopen(一)
    吉他入门第三讲~~~~~和弦
  • 原文地址:https://www.cnblogs.com/yaok430/p/6880855.html
Copyright © 2011-2022 走看看