自我解压脚本

# !/bin/sh

[ $# != "1" ] && echo "Usage: extend.sh tarfile" && exit 0

FILENAME="$1.sh"
echo "# !/bin/sh" > $FILENAME
echo "LINES=\`wc -l \$0 | awk '{ print \$1 }'\`" >> $FILENAME
echo "LINES=\`expr \$LINES - 6\`" >> $FILENAME
echo "tail -n \$LINES \$0 > _TEMP_.tar " >> $FILENAME
echo "tar xvf _TEMP_.tar" >> $FILENAME
echo "rm _TEMP_.tar" >> $FILENAME
echo "exit 0" >> $FILENAME

chmod +x $FILENAME
cat $1 >> $FILENAME