恩,就这么开始了
首先说一下这个小小的插曲。。。写着写着,它就崩溃了,然后我也崩溃了。。。崩溃的我到处找一个不会让我崩溃的工具,然后找来找去就找到了scribefire。
1. 关于从Command Line取参数进来
~ Shell Built in Variables | ~ Meaning |
$# | Number of command line arguments. |
$? | Exit Status |
$* | string that contains all arguments to shell |
$@ | Same as above, except when quoted. |
$- | Option supplied to shell |
$$ | PID of shell |
$! | PID of last started background process (started with &) |
另外,还有$1,$2,$3...代表低N个参数。
2. 关于方括号
这货是一个函数!它不是符号!不是符号!它等同于test命令,那个吧,你要是不给它整个空格啥的,等着报错吧,解释器会告诉你找不到符号啊啊啊。
#!/bin/sh
#
#Script to test if..elif...else if [ $# -eq 0 ]
then
echo "$0 : You must give one integers!"
exit 1
fi if [ $1 -gt 0 ]
then
echo "$1 is positive"
elif [ $1 -lt 0 ]
then
echo "$1 is negative"
elif [ $1 -eq 0 ]
then
echo "$1 -eq 0"
else
echo "Opps! $1 is not number, give number please!"
fi
千万记得`[`后面要加空格,`]`前面也要空格啊啊啊。
3.
有事先放一下:
source
http://linux.vbird.org/linux_server/0250simple_firewall.php
http://tille.garrels.be/training/bash/
http://freeos.com/guides/lsst/index.html
http://www.hlevkin.com/Shell_progr/hellobash.htm
http://www.cyberciti.biz/faq/bash-for-loop/
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.ibm.com/developerworks/linux/library/l-bash/index.html