编写1个弹出式菜单的shell程序并实现其简单的菜单功
编写1个弹出式菜单的shell程序并实现其简单的菜单功能:
*******************************************************
* MENU *
* 1.copy 2.rename *
* 3.remove 4.find *
* 5.exit *
*******************************************************
即用户按下数字1,则提示用户输入源和目的文件名后执行复制;输入数字2,则提示用户输入要更名的文件或目录后执行更名操作;输入数字3,则提示用户输入要删除的文件并执行删除操作;输入数字4,则提示用户输入要查找的文件并执行查找操作;输入数字5,则退出该菜单shell程序的执行。
答:
#! /bin/sh - clear while [ 0 ]; do echo "************************************************" echo " menu " echo " 1.copy 2.rename " echo " 3.remove 4.find " echo " 5.exit " echo "************************************************" echo echo -n " select:" read choice echo case $choice in 1) echo -n "source file:" read src echo echo -n "destination fold:" read des cp -arf $src $des if $?; then echo "copy sucessful!" else echo " copy fail" fi;; 2) echo -n "the file to be renamed:" read src echo echo -n "the new file:" read des mv $src $des if $?; then echo "rename sucessful!" else echo " rename fail" fi;; 3) echo -n "the file to be removed:" read src rm -rf $src if $?; then echo "remove sucessful!" else echo " remove fail" fi;; 4) echo -n "the file to be found:" read src find $HOME -name $src;; 5) exit;; *) echo "Invalid option";; esac done
答案
暂无答案