junxnone / xwiki

https://junxnone.github.io/xwiki/
0 stars 0 forks source link

Programing Shell case #103

Open junxnone opened 4 years ago

junxnone commented 4 years ago

Shell case

#!/bin/bash
case $1 in
    1)
        echo '2'
        ;;
    2)
        echo '3'
        ;;
    *)
        echo 'haha'
esac

read input

#!/bin/bash

echo '
#############################
    1.banana
    2.apple
    3.pear
    4.cherry
#############################
'
read -p "please select a fruit:" fruit

case $fruit in
    1)
        echo 'eat banana'
        ;;
    2)
        echo 'eat apple'
        ;;
    3)
        echo 'eat pear'
        ;;
    4)
        echo 'eat cherry'
        ;;
    *)
        echo 'eat nothing'
esac
source test_case.sh

#############################
    1.banana
    2.apple
    3.pear
    4.cherry
#############################

please select a fruit:1
eat banana

Reference

junxnone commented 4 years ago

junxnone/linuxwiki#23