linux 系统相关 | 说明 |
---|---|
/etc/init.d | linux系统服务启动的接口所在的位置 |
/etc/init.d/syslogd restart or /etc/init.d/rsyslogd restart |
重新启动系统注册表 |
1 执行 shell 脚本
/home/anderson/sheel.sh
1 | # 方式一:绝对路径 |
注意:以上方式都会让脚本在bash子程序中执行,这意味着那是一个全新的bash环境
2 实战example
NO.1 This program shows “Hello World!” in your screen.
1 |
|
NO.2 User inputs the first name and last name.The program output it all.
1 |
|
NO.3 Program creates three files,which named by user’s input and date command.
1 |
|
NO.4 User inputs 2 integer numbers;program will cross those two numbers.
1 |
|
注意:var=$((算式))
方式可以取代declare -i var=$var1...$varn
NO.6 This program shows user’s choice.
1 |
|
NO.7 Program shows this script’s name,parametrs……
1 |
|
1 | anderson@anderson-Sailing-Series:~/sheelscript$ ./sh07.sh hh aa ff |
NO.8 This program shows how shift works.
1 |
|
1 | anderson@anderson-Sailing-Series:~/sheelscript$ ./sh08.sh a b c d e f g |
NO.9 This program shows how shift works.
1 |
|
NO.10 Use netstat and grep to detect WWW,SSH,FTP and MAIL
1 |
|
NO.12 This scripts only accepts the flowing parameters:one,two,three.
1 |
|
NO.12-2 This scripts only accepts the flowing parameters:one,two,three.
1 |
|
NO.12-3 Use function to repeat information.
1 |
|
NO.13 This program will keep ask the user to input string until recive “yes” or “YES”
1 |
|
NO.13-2 This program will keep ask the user to input string until recive “yes” or “YES”
1 |
|
NO.14 Use loop to calcute “1+2+…+100” result.
1 |
|
NO.15 Use for … loop to print 3 animals
1 |
|
NO.16 Use id,figure command to check sysem acccount’s information.
1 |
|
NO.17 Use ping command to check the network’s pc state.
1 |
|
NO.18 User input dir name,I find the permition of files.
1 |
|
NO.19 Try to calculate 1+2+…+${your_input}
1 |
|
3 利用test指令的测试功能:
1 | $ test -e /home/anderson && echo "exist" || echo "not exist" # 测试/home/anderson档名是否存在 |
某种类型的档案是否存在
两个档案之间的比较 && 档案权限的侦测
两个整数之间的比较 && 判定字符串的数据 && 多重条件判断
4 利用判断符 [ ] []
1 | $ [ -z "$HOME" ] ; echo $? <==> $ test -n "$HOME";echo $? # 判断$HOME是否为空 |
注意事项
5 shift:参数变量号码偏移
6 条件判断式
单重
1 | [ $yn == "Y" -o $yn == "y" ] <==>[$yn == "Y" ] || [ $yn == "y" ] |
双重
1 | if [$yn == "Y" ] || [ $yn == "y" ];then |
7 netstat -tuln
8 case……esac
1 | case $1 in |
9 function
Demo1
1 |
|
Demo2
1 |
|
10 循环
while
Demo1
1 |
|
Demo2
1 |
|
until
1 |
|
11 sheelscripts 的追踪与debug
1 | $ sh -n aa.sh |