开发者

how to check if a path is actual or symbolic link

开发者 https://www.devze.com 2023-01-03 03:02 出处:网络
I am writing my own shell program. I am currently implementing the cd command using chdir. I want to implement the cd with the below options :

I am writing my own shell program. I am currently implementing the cd command using chdir. I want to implement the cd with the below options :

When a given path is entered on the shell, how to figure out if the path is a symbolic link or an absolute path progamatically?

Thanks


Check out the lstat() function , you need to use S_ISLNK on the st_mode field.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消