使用Linux的過程中,我們學會一些批處理是對我們的高校辦公有幫助的
if語句:
#!/bin/bash
echo "Please input a integer(0-100):"
read score
if [ "$score" 0 -o "$score" -gt 100 ]
then
echo "The score what you input is not a integer or the score is not in (0-100)."
elif [ "$score" -ge 90 ]
then
echo "The grade is A."
elif [ "$score" -ge 80 ]
then
echo "The grade is B."
elif [ "$score" -ge 70 ]
then
echo "The grade is C."
elif [ "$score" -ge 60 ]
then
echo "The grade is D."
else
echo "The grade is E."
fi
案例:
#!/bin/bash
# 啓動另一版本的Android Studio
echo "What do you want to do next?"
echo "-1 Run Android Studio 3.0"
echo "-2 Run Android Studio 3.0 background"
read sel
if [ "$sel" -eq 1 ]
then
bash /usr/local/android-studio/bin/studio.sh
echo "Android studio 3.0 has been started."
elif [ "$sel" -eq 2 ]
then
nohup bash /usr/local/android-studio/bin/studio.sh >/dev/null 2>&1 &
echo "Android studio 3.0 has been started."
fi