[ 和 test 命令是同一个命令吗?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
redhatlinux10
帖子: 773
注册时间: 2008-01-22 23:24
来自: 三亚
联系:

[ 和 test 命令是同一个命令吗?

#1

帖子 redhatlinux10 » 2011-11-15 12:38

在我的sles 11机器上,[ 和 test 是shell的内置命令。尽管它们都有非内置的版本。

代码: 全选

linux-mage:~ # type [
[ is a shell builtin
linux-mage:~ # type test
test is a shell builtin
我的疑问是:
1,当运行的都是内置版本时,这两个命令是同一个命令吗?或者这么说,[ 和 test 只是同一段代码的不同名字而已?
2,当运行的都是非内置版本时,我发现 [ 和 test 是两个不同的命令,并不是网上有些文章说的那样,[是test的符号链接。为什么要实现两个命令,用符号链接不是挺好的吗?

代码: 全选

linux-mage:~ # ll /usr/bin/[
-rwxr-xr-x 1 root root 31432 Feb 21  2009 /usr/bin/[
linux-mage:~ # ll /usr/bin/test
-rwxr-xr-x 1 root root 31416 Feb 21  2009 /usr/bin/test
3,点命令和source命令的情况是否也和上述一样?
回复