深入探索 test 命令:文件测试与比较的实用指南
1. test 命令简介
test 命令是一个强大的工具,用于在脚本中进行条件测试。它通常作为 shell 内置命令实现,也有对应的磁盘文件 /usr/bin/test 。 [ 是 test 的别名,调用时需要在参数周围加上 ] 。
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
$ which test
/usr/bin/test
$ which [
/usr/bin/[
$ ls -il /usr/bin/test /usr/bin/[
33625 -rwxr-xr-x 1 root root 33064 Apr 28 2010 /usr/bin/[
33634 -rwxr-xr-x 1 root root 30136 Apr 28 2010 /usr/bin/test
2. 文件类型测试
在 Unix 和 Linux 系统中,一切皆文件。 test 命令提供了多种标志来测试文件的不同类型。
- 文件存在性测试 :
- -e 或 -a 标志用于测试文件是否存在。
超级会员免费看
订阅专栏 解锁全文
1649

被折叠的 条评论
为什么被折叠?



