ABS GUID 例2-3的疑问
发表于 : 2010-07-22 15:14
刚开始学习SHELL,看的书本是Advanced BASH Scripting Guide 4.0
在运行例2-3的script的时候遇到如下提示
[: 22: Illegal number:
Logs cleaned up.
网上很难查到这个提示的成因,还望各位大虾赐教。
例2-3的代码如下
原来的例子中还有一部分注释因为太长被我去掉了。
把注释# Run as root, of course. 下面的5行程序注释掉之后,原来的提示“[: 22: Illegal number: ”也没有了,请问是什么原因呢?
在运行例2-3的script的时候遇到如下提示
[: 22: Illegal number:
Logs cleaned up.
网上很难查到这个提示的成因,还望各位大虾赐教。
例2-3的代码如下
代码: 全选
#!/bin/bash
# Cleanup, version 3
# Warning:
# -------
# This script uses quite a number of features that will be explained
#+ later on.
# By the tim you've finished the first half of the book,
#+ there should be nothing mysterious about it.
LOG_DIR=/var/log
ROOT_UID=0 # Only users with $UID 0 have root privileges.
LINES=50 # Default number of lines saved.
E_XCD=66 # Can't change directory?
E_NOTROOT=67 # Non-root exit error.
# Run as root, of course.
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ -n "$1" ]
# Test if command line argument present (non-empty).
then
lines=$1
else
lines=$LINES # Default, if not specified on command line.
fi
cd $LOG_DIR
if [ `pwd` != "$LOG_DIR" ] # or if [ "$PWD" != "$LOG_DIR" ]
# Not in /var/log?
then
echo "Can't change to $LOG_DIR."
exit $E_XCD
fi # Doublecheck if in right directory, before messing with log file.
tail -$lines messages > mesg.temp # Saves last section of message log file.
mv mesg.temp messages # Become new log directory.
cat /dev/null > wtmp # ': > wtmp' and '> wtmp' have the same effect.
echo "Logs cleaned up."
exit 0
# A zero return value from the script upon exit
#+ indicates success to the shell.
把注释# Run as root, of course. 下面的5行程序注释掉之后,原来的提示“[: 22: Illegal number: ”也没有了,请问是什么原因呢?