gpt4 book ai didi

shell - 在unix工作目录中查找特定目录

转载 作者:行者123 更新时间:2023-12-02 14:44:35 25 4
gpt4 key购买 nike

我想检查当前工作目录中是否存在名为“name”的目录。可以用ls来做吗?

   ls -l | grep ^-d

仅显示目录,但如何指定?

提前致谢

最佳答案

One should never parse the output of ls 。如果您使用的是 bash,请尝试这个

if [ -d "$DIRECTORY" ]; then
# will enter here if $DIRECTORY exists.
fi

关于shell - 在unix工作目录中查找特定目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16361381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com