- shell还是一个功能相当强大的编程语言、易编写、易调试、灵和性强
[root@slave2 ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash [root@slave2 bin]# ll | grep bash -rwxr-xr-x. 1 root root 964544 Apr 10 2018 bash lrwxrwxrwx. 1 root root 10 Jul 2 2018 bashbug -> bashbug-64 -rwxr-xr-x. 1 root root 6964 Apr 10 2018 bashbug-64 lrwxrwxrwx. 1 root root 4 Jul 2 2018 sh -> bash
[root@slave2 ~]# vim helloworld.sh # 在helloworld.sh中输入如下内容 #!/bin/bash echo 'hello world!'
脚本的常用执行方式
- 采用bash或sh+脚本的相对路径或绝对路径(不用赋予脚本+x权限)
[root@slave2 ~]# bash helloworld.sh hello world! [root@slave2 ~]# sh helloworld.sh hello world! [root@slave2 ~]# pwd /root [root@slave2 ~]# bash /root/helloworld.sh hello world! [root@slave2 ~]# sh /root/helloworld.sh hello world!
-
# 无执行权限 -rw-r--r--. 1 root root 32 Jan 18 07:12 helloworld.sh [root@slave2 ~]# ./helloworld.sh -bash: ./helloworld.sh: Permission denied # 为helloworld.sh添加执行权限 [root@slave2 ~]# chmod 777 helloworld.sh -rwxrwxrwx. 1 root root 32 Jan 18 07:12 helloworld.sh [root@slave2 ~]# ./helloworld.sh hello world! [root@slave2 ~]# /root/helloworld.sh hello world!
-
#!/bin/bash cd /root/testshell/ touch banzhang.txt echo 'I love cls' >> banzhang.txt