輸出hello world
vi test1
vi界面中編寫shell,必須以#! /bin/sh開頭
#! /bin/sh
$i="Hello World"
echo "$i"
儲存退出
chmod 777 test1
./test1 檢視是否輸出Hello World
----------------------------------------------------------------
檢視shell的目錄是否為/bin/bash
vi test2
vi編輯
#! /bin/sh
if [ "$SHELL"="/bin/bash" ];then echo "your SHELL src is /bin/sh"
else
echo "your SHELL src $SHELL"
fi
同樣執行 chmod 777 test2 接着./test2
----------------------------------------------------------------
vi test3
vi 編輯
#! /bin/sh
mailfolder=/root/Desktop/mailfile
[ -r "$mailfolder"] || { echo "can not read $mailfolder ";exit 1; }
content=`cat $mailfolder` && content="${content#From}"
echo "$mailfolder has mail from : $content"
----------------------------------------------------------------
vi test4
vi 編輯
#! /bin/sh
in="$1"
case "$1" in
*1*)
echo "input has 1" ;;
*2*)
echo "input has 2" ;;
*3*)
echo "input has 3" ;;
*)
echo "input has $1" ;;
esac
----------------------------------------------------------------