LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 985|回复: 8

who can explain this test condition: [ -h "$element" -a ! -e

[复制链接]
发表于 2006-9-11 22:38:24 | 显示全部楼层 |阅读模式
This test condition is come from Example 7-4. Testing for broken links
in http://www.tldp.org/LDP/abs/html/fto.html
I know the meaning of "-h", "-a", "!" and "-e", but I don't know the
meaning of the test condition of putting them together.

This is my understanding:
-h "$element" : test if "$element" is a symbolic link;
! -e "$element" : test if "$element" isn't exist;

But, I can't understand this entire test condition, who can give a
explain? thanks.
发表于 2006-9-11 23:21:12 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2006-9-12 04:30:43 | 显示全部楼层
Post by littlebat
This test condition is come from Example 7-4. Testing for broken links
in http://www.tldp.org/LDP/abs/html/fto.html
I know the meaning of "-h", "-a", "!" and "-e", but I don't know the
meaning of the test condition of putting them together.

This is my understanding:
-h "$element" : test if "$element" is a symbolic link;
! -e "$element" : test if "$element" isn't exist;

But, I can't understand this entire test condition, who can give a
explain? thanks.

This is to test if a symlink is pointing to a non-existing file. You can create a file and then symlink it. Test with this statement and then remove the file and then test again.
回复 支持 反对

使用道具 举报

发表于 2006-9-12 09:02:56 | 显示全部楼层
的确是这样,但是我比较疑惑,为什么会是如此效果阿,按道理来说
symbol link本身就是一个文件阿,-e "$element"应该测试的是symbol link文件本身阿?
回复 支持 反对

使用道具 举报

发表于 2006-9-12 10:03:34 | 显示全部楼层
"symbol link本身就是一个文件阿",我不晓得这种说法对不对,但测试"symbol link文件本身"存在与否是没有意思的,关键是指向的链接文件存在不存在.
回复 支持 反对

使用道具 举报

发表于 2006-9-12 10:07:25 | 显示全部楼层
Post by Iambitious
的确是这样,但是我比较疑惑,为什么会是如此效果阿,按道理来说
symbol link本身就是一个文件阿,-e "$element"应该测试的是symbol link文件本身阿?

symlink is actually a pointer pointing to the path of the target file, all filesystem functions will act on the real file directly and transparently.
回复 支持 反对

使用道具 举报

发表于 2006-9-12 11:18:26 | 显示全部楼层
哦,我明白了,看来是我对symbol link理解的不对了。谢谢了!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-12 23:34:48 | 显示全部楼层
谢谢各位啦,虽然对符号链接和它链接的真实文件的关系还是不大明白。
我可以暂时把[ -e "$element" ] 理解为:测试一个链接符号(文件)存在与否就是测试它所代表的真实文件是否存在;也没有一个东西用来专门测试链接符号是否存在。

我对yongjian的
               
symlink is actually a pointer pointing to the path
of the target file, all filesystem functions will
act on the real file directly and transparently.

还有点异议,像作用在符号链接上的rm, mv等命令就是对链接符号操作的,而像vi等命令才是对真实文件操作的。
回复 支持 反对

使用道具 举报

发表于 2006-9-12 23:51:46 | 显示全部楼层
rm,mv对文件的inode操作
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表