1、使用set命令来观察脚本运行情况
源码:
#!/bin/sh
set -x
echo -n "Can you write device drivers? "
read answer
answer=`echo $answer | tr [a-z] [A-Z]`
#echo $answer
if [ "$answer" = Y ]
then
echo "Wow, you must be very skilled"
else
echo "Neither can I, I'm just an example shell script"
fi
运行:
[apache@indigo shell]$ sh example.sh
+ echo -n 'Can you write device drivers? '
Can you write device drivers? + read answer
Y
++ echo Y
++ tr '[a-z]' '[A-Z]'
+ answer=Y
+ '[' Y = Y ']'
+ echo 'Wow, you must be very skilled'
Wow, you must be very skilled
[apache@indigo shell]$ sh example.sh
+ echo -n 'C