shell脚本学
2016/02/10 17:46 -
1.
1. a=10
2. echo -e "Value of a is $a \n"
3. 这里 -e 表示对转义字符进行替换。如果不使用 -e 选项,将会原样
件的各种属性:
1. #!/bin/sh
2. file="/var/www/tutorialspoint/unix/"
3. if[ -r $file]
4. then
5. echo "File has read access"
6. else
7. echo "File does not have read access"
8. fi
9. if[ -w $file]
10. then
11. echo "File has write permission"
12. else
13. echo "File does not have write permission"
14. fi
15. if[ -x $file]
16. then
17. echo "File has execute permission"
18. else
19. echo "File does not have execute permission"
20. fi
21. if[ -f $file]
22. then
23. echo "File is an ordinary file"
24. else
25. echo "This is sepcial file"
26. fi
27. if[ -d $file]
28. then
29. echo "File is a directory"
30. else
31. echo "This is not a directory"
32. fi
33. if[ -s $file]
34. then
35. echo "File size is zero"
36. else
37. echo "File size is not zero"
38. fi
39. if[ -e $file]
40. then
41. echo "File exists"
42. else
43. echo "File does not exist"
44. fi运行结果:
File has read access
File has write permission
File has execute permission
File is an ordinary file
This is not a directory
File size is zero
File exists
文件测试运算符列表
操作符 说明 举例
-b file 检测文件是否是块设备文件,如果是,则返回 true。
shell脚本学习笔记 来自淘豆网m.daumloan.com转载请标明出处.