说我有一个符号链接:
/path/to/foo->/path/to/some_file.txt
假设我有一个shell变量x=/path/to/foo
,如何获得some_file.txt
一个shell变量y
?
在zsh
,
y=${x:A:t}
将扩展到绝对路径的尾部$x
。some_file.txt
除非some_file.txt
它本身是指向其他事物的符号链接,否则它将如此。
否则,您可以使用zsh
zstat
内置的:
zmodload zsh/zstat
zstat -A y +link -- $x && y=$y:t
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句