|
[root@garytao-01 ~]# mkdir shell [root@garytao-01 ~]# cd shell/
[root@garytao-01 shell]# ls
[root@garytao-01 shell]# vi 01.sh
[root@garytao-01 shell]# 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.00s 0.03s 0.01s w
01.sh
[root@garytao-01 shell]# cat 01.sh
#!/bin/bash //第一行这个如果在本面执行可不写,执行脚本时加/bin/bsah就可以
echo "123"
w
ls
[root@garytao-01 shell]# chmod a+x 01.sh
[root@garytao-01 shell]# ./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.00s 0.02s 0.00s /bin/bash ./01.sh
01.sh
[root@garytao-01 shell]# ls -l /bin/bash
-rwxr-xr-x. 1 root root 960392 8月 3 2016 /bin/bash
[root@garytao-01 shell]# ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 10月 17 05:04 /bin/sh -> bash
[root@garytao-01 shell]# /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.00s 0.03s 0.00s w
01.sh
#查看脚本执行过程
[root@garytao-01 shell]# 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.00s 0.04s 0.01s w
+ ls
01.sh
#检查脚本语法错误
[root@garytao-01 shell]# bash -n 01.sh
[root@garytao-01 shell]# /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.00s 0.05s 0.00s /bin/bash /root/shell/01.sh
01.sh
|
|
|