输出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
----------------------------------------------------------------