linux的shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量
# mkdir shell # cd shell/# ls
# vi 01.sh
# bash 01.sh
123
10:57:41 up 9 min,1 user,load average: 0.00, 0.13, 0.13
USER TTY FROM LOGIN@> root pts/0 172.16.111.1 10:49 5.00s0.03s0.01s w
01.sh
# cat 01.sh
#!/bin/bash //第一行这个如果在本面执行可不写,执行脚本时加/bin/bsah就可以
echo "123"
w
ls
# chmod a+x 01.sh
# ./01.sh
123
10:58:12 up 9 min,1 user,load average: 0.00, 0.11, 0.12
USER TTY FROM LOGIN@> root pts/0 172.16.111.1 10:49 4.00s0.02s0.00s /bin/bash ./01.sh
01.sh
# ls -l /bin/bash
-rwxr-xr-x. 1 root root 960392 8月 3 2016 /bin/bash
# ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 10月 17 05:04 /bin/sh -> bash
# /bin/bash 01.sh
123
11:02:12 up 13 min,1 user,load average: 0.00, 0.05, 0.10
USER TTY FROM LOGIN@> root pts/0 172.16.111.1 10:49 4.00s0.03s0.00s w
01.sh
#查看脚本执行过程
# bash -x 01.sh
+ echo 123
123
+ w
11:12:04 up 23 min,1 user,load average: 0.00, 0.03, 0.07
USER TTY FROM LOGIN@> root pts/0 172.16.111.1 10:49 4.00s0.04s0.01s w
+ ls
01.sh
#检查脚本语法错误
# bash -n 01.sh
# /root/shell/01.sh
123
11:23:45 up 35 min,1 user,load average: 0.05, 0.05, 0.06
USER TTY FROM LOGIN@> root pts/0 172.16.111.1 10:49 1.00s0.05s0.00s /bin/bash /root/shell/01.sh
01.sh
页:
[1]