1. 程式人生 > >Linux bash初學-case語句

Linux bash初學-case語句

linux bin inux vim teacher 編寫 簡單 eache hello

編寫一個簡單的bash腳本hello.sh,提供如下特性:

1. 當運行./hello.sh student , 輸出為 teacher

2. 當運行./hello.sh teacher, 輸出為 student

3. 當沒有任何參數,或參數不是teache 或者 student 時,在控制臺打印輸出如下信息:

./hello.sh student | teacher

#!/bin/bash
case $1 in
    teacher)
        echo "student"
    ;;
    student)
        echo "teacher"
    ;;
    *)
        echo "./hello.sh student | teacher"
    ;;
esac

xiejiaohui-2:~ xiejiaohui$ vim hello.sh

xiejiaohui-2:~ xiejiaohui$ ./hello.sh

./hello.sh teacher | student

xiejiaohui-2:~ xiejiaohui$ ./hello.sh student

teacher

xiejiaohui-2:~ xiejiaohui$ ./hello.sh teacher

student

xiejiaohui-2:~ xiejiaohui$

Linux bash初學-case語句