解析了什么?

ech*_*cho 0 bash

当我运行以下命令时:

if [ -d "~/Desktop" ]; then echo "exists"; fi
if [ -d "/bin" ]; then echo "exists"; fi
Run Code Online (Sandbox Code Playgroud)

第一个命令没有回音,第二个命令"存在".为什么bash不理解"〜"?似乎

if [ -d ~/Desktop ]; then echo "exists"; fi
if [[ -d ~/Desktop ]]; then echo "exists"; fi
Run Code Online (Sandbox Code Playgroud)

将工作.是否可以使用〜?shell是bash.谢谢!

NPE*_*NPE 5

~不会在引号内扩展.尝试

if [ -d "$HOME/Desktop" ]; then echo "exists"; fi
Run Code Online (Sandbox Code Playgroud)