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循环实现