如何检查的路径是实际或符号链接(how to check if a path is actual o

2019-10-23 03:31发布

我写我自己的shell程序。 我使用CHDIR目前正在实施的cd命令。 我想实现与下面的选项CD:

  • -P不要跟随符号链接
  • -L跟踪符号链接(默认)

当在外壳中输入一个给定的路径,如何找出如果路径是一个符号链接或progamatically绝对路径?

谢谢

Answer 1:

退房LSTAT()函数,你需要使用S_ISLNK在st_mode字段。



Answer 2:

if [ -L /path/to/file ]; then
  echo "is a symlink!"
else
  echo "not a symlink! maybe a directory or regular file, or does not exist"
end


文章来源: how to check if a path is actual or symbolic link
标签: unix symlink