1.修改当前目录
#! /bin/sh
dir1=/usr/local
dir2=/var/spool
pushd $dir1
echo "Now in direcory `pwd`."
pushd $dir2
echo "Now in directory `pwd`."
echo "The top entry in the DIRSTACT array is $DIRSTACK."
popd
echo "Now back in directory `pwd`."
popd
echo "Now back in original working directory `pwd`."
exit 0
2.let 命令
#! /bin/sh
echo
let a=11
let a=a+5
echo "11 + 5 = $a"
let "a <<= 3"
echo "/"/$a/" (=16) left-shifted 3 places = $a"
let "a /= 4"
echo "128 / 4 = $a"
let "a -= 5"
echo "32 - 5 = $a"
let "a *= 10"
echo "27 * 10 = $a"
let "a %= 8"
echo "270 modulo 8 = $a (270 / 8 = 33,remainder $a)"
echo
exit 0
3.eval命令
#! /bin/sh
y=`eval ls -l`
echo $y
echo "--------1-----------"
echo "$y"
echo "----------2-------"
echo;echo
y=`eval df`
echo $y
echo
echo "=================================="
echo
for i in 1 2 3 4 5
do
eval value=$i
echo $value
done
echo
echo "-----"
echo
for i in ls df
do
value=eval $i
value=$i
echo $value
done
exit 0
4.强制退出
#! /bin/sh
killppp="eval kill -9 `ps ax | awk '/ppp/ { print $1 }'`"
$killppp
chmod 666 /dev/tty$3
rm /var/lock/LCK..tty$3
exit 0
5.另一个"rot13"版本
#! /bin/sh
setvar_rot_13(){
local varname=$1 varvalue=$2
eval $varname='$(echo "$varvalue" | tr a-z n-za-m)'
}
setvar_rot_13 var "foobbar"
echo $var
setvar_rot_13 var "$var"
echo $var
exit 0