我注意到 find -execdir 是不可移植的,所以我决定找到一种可移植的方式来使用 find -exec 来达到相同的效果。为此,必须能够确定“find”找到的从“/”到目录的路径是否包含任何符号链接,如果包含则拒绝遍历它。我编写了一个小脚本来确定给定路径是否包含符号链接,但无论我给出什么,它似乎总是返回代码 1。不会触发任何打印任何内容的命令,除非我给它一个非目录,在这种情况下会触发第一个 printf 命令。
#!/bin/sh -e
# If any commands fail, the script should return a nonzero status
[ -d "$1" ] || printf "%s is not a directory" "$1" && exit 1 # Tests if argument is a directory
cd "$1" || echo "Could not change directory" && exit 1 # If it is a directory, goes to it
until [ "$PWD" = '/' ] # Loop until root directory reached
do
cd .. || echo "Could not change directory" && exit 1 # Go to parent directory
[ -d "$PWD" ] || printf "%s is not directory" "$PWD" && exit 1 # Check that this is a directory
done
echo "Given an okay directory"
exit 0