Shell script 自動插入資料的一些問題 - Linux

By Bethany
at 2012-08-23T09:08
at 2012-08-23T09:08
Table of Contents
※ 引述《nashsai (神佛兩光NANA)》之銘言:
: #!/bin/sh
: echo "MAIN MENU"
: echo "0. exit"
: echo "1. aaa"
: echo "2. bbb"
: echo "3. ccc"
: read -p "please enter option" opt
: case $opt in
: 0) exit ;;
: 1) /usr/local/sbin/aaa ;;
: 2) /usr/local/sbin/bbb ;;
: 3) /usr/local/sbin/ccc ;;
: *) echo "$opt is a invalid option, please [enter] key continue"
: /usr/local/sbin/test ;;
: esac
==================>
$ cat menu-list.txt
aaa
bbb
ccc
==================>
$ cat menu.sh
#!/bin/bash
MENU="MAIN MENU
0) exit"
CASE="case \$opt in
0) exit ;;"
# main
let c=1
for i in $(cat menu-list.txt); do
MENU="$MENU
$c) $i"
CASE="$CASE
$c) echo /usr/local/sbin/$i;;"
let c=c+1
done
CASE="$CASE
*) echo \"\$opt is a invalid option, please [enter] key continue\"
#/usr/local/sbin/test ;;
esac"
echo "$MENU"
read -p "please enter option: " opt
#echo "$CASE"
eval "$CASE"
=========>
$> echo ddd >> menu-list.txt
$> ./menu.sh
MAIN MENU
0) exit
1) aaa
2) bbb
3) ccc
4) ddd
please enter option:
--
: #!/bin/sh
: echo "MAIN MENU"
: echo "0. exit"
: echo "1. aaa"
: echo "2. bbb"
: echo "3. ccc"
: read -p "please enter option" opt
: case $opt in
: 0) exit ;;
: 1) /usr/local/sbin/aaa ;;
: 2) /usr/local/sbin/bbb ;;
: 3) /usr/local/sbin/ccc ;;
: *) echo "$opt is a invalid option, please [enter] key continue"
: /usr/local/sbin/test ;;
: esac
==================>
$ cat menu-list.txt
aaa
bbb
ccc
==================>
$ cat menu.sh
#!/bin/bash
MENU="MAIN MENU
0) exit"
CASE="case \$opt in
0) exit ;;"
# main
let c=1
for i in $(cat menu-list.txt); do
MENU="$MENU
$c) $i"
CASE="$CASE
$c) echo /usr/local/sbin/$i;;"
let c=c+1
done
CASE="$CASE
*) echo \"\$opt is a invalid option, please [enter] key continue\"
#/usr/local/sbin/test ;;
esac"
echo "$MENU"
read -p "please enter option: " opt
#echo "$CASE"
eval "$CASE"
=========>
$> echo ddd >> menu-list.txt
$> ./menu.sh
MAIN MENU
0) exit
1) aaa
2) bbb
3) ccc
4) ddd
please enter option:
--
Tags:
Linux
All Comments

By Lily
at 2012-08-24T08:20
at 2012-08-24T08:20
Related Posts
Windows端的網路印表機

By Madame
at 2012-08-22T18:54
at 2012-08-22T18:54
resource0 可以砍掉嗎???

By William
at 2012-08-22T18:45
at 2012-08-22T18:45
/usr/bin/make 套件

By Gary
at 2012-08-22T10:19
at 2012-08-22T10:19
有關顯卡驅動程式

By Franklin
at 2012-08-22T04:06
at 2012-08-22T04:06
自己寫的「遊戲剋星」

By Kama
at 2012-08-21T13:09
at 2012-08-21T13:09