[root@linux ~]# sh [-nvx] scripts.sh 選項: -n :不要執行 script,僅查詢語法的問題; -v :執行 sccript 前,先將 script 的內容輸出到螢幕上; -x :將使用到的 script 內容顯示到螢幕上。
[root@linux ~]# sh -n sh16.sh # 若語法沒有問題,則不會顯示任何資訊。 [dywang@dywOffice ~]$ vi sh015.sh 1 #!/bin/bash 2 # Program: 3 # Using for .... loop to print 3 animal 4 # History: 5 # 2005/08/29 csie First release 6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 7 export PATH 8 9 for animal in dog cat elephant 10 do 11 echo "There are ""$animal""s.... 12 done [dywang@dywOffice ~]$ sh -n sh015.sh sh015.sh: line 11: unexpected EOF while looking for matching `"' sh015.sh: line 13: syntax error: unexpected end of file
[dywang@dywOffice ~]$ sh -v sh015.sh
#!/bin/bash
# Program:
# Using for .... loop to print 3 animal
# History:
# 2005/08/29 csie First release
for animal in dog cat elephant
do
echo "There are ""$animal""s...."
done
There are dogs....
There are cats....
There are elephants....
[root@linux ~]# sh -x sh15.sh + PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/csie/bin + export PATH + for animal in dog cat elephant + echo 'There are dogs.... ' There are dogs.... + for animal in dog cat elephant + echo 'There are cats.... ' There are cats.... + for animal in dog cat elephant + echo 'There are elephants.... ' There are elephants.... # 最前面會加上 + 字號表示程式段落。
[root@dywHome ~]# cat /etc/init.d/xfs
#!/bin/sh
#
# xfs: Starts the X Font Server
#
# Version: @(#) /etc/rc.d/init.d/xfs 1.4
#
# chkconfig: 2345 20 10
# description: Starts and stops the X Font Server at boot time and shutdown.
#
# processname: xfs
# config: /etc/X11/fs/config
# hide: true
#
### BEGIN INIT INFO
# Provides: xfs
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Short-Description: X Font Server
# Description: X Font Server
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
# See how we were called.
case "$1" in
start)
gprintf "Starting X Font Server: "
mkdir -p /tmp
chmod a+w,+t /tmp
# sticky(+t):僅有該檔案/目錄建立者與 root 能刪除它。
rm -fr /tmp/.font-unix
daemon --check xfs xfs -port -1 -daemon -droppriv -user xfs
touch /var/lock/subsys/xfs
echo
;;
stop)
gprintf "Shutting down X Font Server: "
killproc xfs
rm -f /var/lock/subsys/xfs
echo
;;
status)
status xfs
RETVAL=$?
;;
restart)
gprintf "Restarting X Font Server. "
if [ -f /var/lock/subsys/xfs -a ! -z "`pidof xfs`" ]; then
killproc xfs -USR1
else
rm -fr /tmp/.font-unix
daemon --check xfs xfs -port -1 -daemon -droppriv -user xfs
touch /var/lock/subsys/xfs
fi
echo
;;
*)
gprintf "*** Usage: xfs {start|stop|status|restart}\n"
exit 1
esac
exit $RETVAL