- Shell 脚本(shell script),是一种为 shell 编写的脚本程序。现有一个test.sh文件,且有可执行权限,文件中内容为:
#!/bin/bash
aa='Hello World !'
请问下面选项中哪个能正常显示Hello World !
A sh test.sh >/dev/null 1 && echo $aa
B. /test.sh >/dev/null 1 && echo $aa
C bash test.sh >/dev/null 1 && echo $aa
D source test.sh >/dev/null 1 && echo $aa
- bash脚本文件一般第一行开头是 #!
- 在bash编程中,算术比较大于、大于等于的运算符分别是 ge gt
- 系统管理员编写扫描临时文件的shell程序tmpsc.sh, 测试该程序时提示拒绝执行,解决的方法有
Achmod 644 tmpsc.sh
B chmod 755 tmpsc.sh
C chmod a+x tmpsc.sh
D chmod u+x tmpsc.sh
读取的权限等于4,用r表示;写入的权限等于2,用w表示;执行的权限等于1,用x表示;
通过4、2、1的组合,得到以下几种权限:0(没有权限);4(读取权限);5(4+1 | 读取+执行);6(4+2 | 读取+写入);7(4+2+1 | 读取+写入+执行)
以755为例:
1-3位7等于4+2+1,rwx,所有者具有读取、写入、执行权限;
4-6位5等于4+1+0,r-x,同组用户具有读取、执行权限但没有写入权限;
7-9位5,同上,也是r-x,其他用户具有读取、执行权限但没有写入权限。
chmod a+x a.txt 等价于 chmod +x a.txt
给所有用户给予a.txt文件可执行权限
chmod u+x a.txt
a.txt文件的所有用户可执行权限
chmod g+x a.txt
a.txt用户组可执行权限
chmod o+x a.txt
a.txt其他用户可执行权限