zoukankan      html  css  js  c++  java
  • shell编程:字符串练习题string.sh

    string.sh脚本

    #!/bin/bash
    #
    
    string="Bigdata process framework is Hadoop,Hadoop is an open source projeck"
    
    function print_tips
    
    {
               echo "**************************************************************"
               echo "(1) 打印string的长度"
               echo "(2) 删除字符串中所有的Hadoop"
               echo "(3) 替换第一个Hadoop为Mapreduce"
               echo "(4) 替换全部的Hadoop为Mapreduce"
               echo "**************************************************************"
    
    }
    
    function len_of_string
    
    {
               echo "${#string}"   
    }
    
    function del_Hadoop
    
    {
               echo "${string//Hadoop/}"
    
    }
    
    function rep_Hadoop_Mapreduce_first
    
    {
               echo "${string/Hadoop/Mapreduce}"
    }
    
    function rep_Hadoop_Mapreduce_all
    
    {
               echo "${string//Hadoop/Mapreduce}"
    }
    
    while true
    
    do
               echo "[string=$string]"
               echo
               print_tips
               read -p "Please input your choice (1|2|3|4|q|Q):" choice
    
               case $choice in
                       
                       1) 
                              len_of_string
                              ;;
                       2)     
                              del_Hadoop
                              ;;
                       3)
                              rep_Hadoop_Mapreduce_first
                              ;;
                       4)      
                              rep_Hadoop_Mapreduce_all
                              ;;
    
                       q|Q) 
                              exit
                              ;;  
                       *)
                        
                              echo "Eroor,inpu only in{1|2|3|4|q|Q}"
                  esac
    
    done

    编写思路:

    1.先把功能函数写出来

    2.跟句要求用choice+while循环实现

  • 相关阅读:
    微信小程序
    微信小程序
    微信小程序
    微信小程序
    es5
    es5
    es5||es6
    es5
    5 个常用的软件质量指标
    Solr
  • 原文地址:https://www.cnblogs.com/soymilk2019/p/11713184.html
Copyright © 2011-2022 走看看