文章

shell交互菜单脚本

shell交互菜单脚本

本文档介绍 shell交互菜单脚本 的相关内容。

shell 交互菜单脚本

### 选择显示 # !/bin/bash # 选择后显示的内容 ALL=" A B C D " # 菜单显示内容 echo -e "1A 2B 3C 4D" read -p "input:" ID # 输入1-4 输出ALL中的A-D echo $ALL | xargs | cut -d ' ' -f $ID
### 选择显示 # !/bin/bash # 选择后显示的内容 ALL=" A B C D " # 菜单显示内容 echo -e "1A\n2B\n3C\n4D" read -p "input:" ID # 输入1-4 输出ALL中的A-D echo $ALL | xargs | cut -d ' ' -f $ID ### 选择设置为变量 # !/bin/bash ALL=" A B C D " echo -e "1A\n2B\n3C\n4D" read -p "input:" ID test1=`echo $ALL | xargs | cut -d ' ' -f $ID` # 设置为变量 echo $test1 ### 多变量 # !/bin/bash ALL=" A B C D " DEE=" E F G H " echo -e "1A\n2B\n3C\n4D" read -p "input:" ID test1=`echo $ALL | xargs | cut -d ' ' -f $ID` test2=`echo $DEE | xargs | cut -d ' ' -f $ID` echo $test1 echo $test2 echo "1,2,3,4" |xargs |cut -d ',' -f 1 # xargs 将echo的内容转换可变换值 , cut -d ',' 以‘,’进行分隔 -f 1 显示分隔后的第一个值
#!/bin/bash # simple script menu function diskapace { clear fdisk -l } function whoseon { clear who am i } function menusage { clear cat /proc/meninfo } select option in "Display disk space" "Display logged on users" "Display memory usage" "Exit menu" do case $option in "Exit menu") break ;; "Display disk space") diskapace ;; "Display logged on users") whoseon ;; "Display memory usage") menusage ;; * ) clear echo "sorry,wrong selection" ;; esac done clear
运行: # ./selectmeun.sh 1) Display disk space 3) Display memory usage 2) Display logged on users 4) Exit menu # ?
本文由作者按照 CC BY 4.0 进行授权