先看两个示例:
root@sunweikai-virtual-machine:/home/missing# pwd
/home/missing
root@sunweikai-virtual-machine:/home/missing# echo '$pwd'
$pwd
root@sunweikai-virtual-machine:/home/missing# echo "$pwd"
根据输出发现,双引号输出的是环境变量,单引号原样输出
root@sunweikai-virtual-machine:/home/missing# $HOME
bash: /root: Is a directory
root@sunweikai-virtual-machine:/home/missing# echo "$HOME"
/root
root@sunweikai-virtual-machine:/home/missing# echo '$HOME'
$HOME
双引号输出环境变量,单引号原样输出,直接输出路径文件
由上可知 "$HOME" 可以输出环境变量即路径,因此 $HOME 可以作为路径使用