How to check if two paths are equal in Bash?

前端 未结 5 623
渐次进展
渐次进展 2021-01-03 20:54

What\'s the best way to check if two paths are equal in Bash? For example, given the directory structure

~/
  Desktop/
    Downloads/ (symlink to ~/Downloads         


        
5条回答
  •  礼貌的吻别
    2021-01-03 21:36

    Bash's test commands have a -ef operator for this purpose

    if [[ ./ -ef ~ ]]; then ...
    
    if [[ ~/Desktop -ef /home/you/Desktop ]]; then ...
    

    etc...

    $ help test | grep -e -ef
          FILE1 -ef FILE2  True if file1 is a hard link to file2.
    

提交回复
热议问题