1.使用多条命令
如果想将两条命令一起运行,可以将他们输入到同行中,并用分号(;)隔开:
[root@localhost ~]# data;who bash: data: command not found root pts/1 2014-11-06 09:03 (192.168.18.22)
2.创建脚本文件
创建脚本文件时,必须在文件中的第一行指明所使用的shell,格式如下:
#!/bin/bash 在普通的shell脚本中,用#号作注释行!#号后面加感叹号!告诉shell运行下列脚本shell [root@localhost ~]# cat 1.sh #!/bin/bash #This script displays the date and who's logged on data who
3.创建好shell脚本文件后,还有一个问题!shell指出我没有执行该文件的权限?
[root@localhost ~]# ./1.sh bash: ./1.sh: 权限不够 [root@localhost ~]# ls -l 1.sh -rw-r--r-- 1 root root 73 11-06 14:48 1.sh 下一步赋予自己执行该文件的权限,使用chmod命令 [root@localhost ~]# chmod u+x 1.sh [root@localhost ~]# ls -l 1.sh -rwxr--r-- 1 root root 73 11-06 14:48 1.sh 开始执行脚本 [root@localhost ~]# ./1.sh 2014年 11月 06日 星期四 14:52:50 CST root pts/1 2014-11-06 09:03 (192.168.18.22)
转载于:https://blog.51cto.com/liangey/1573432