This question already has answers here:
Tilde in path doesn't expand to home directory
                                
                                    (4个答案)
                                
                        
                                5年前关闭。
            
                    
有人可以帮我找到这段代码的问题吗?收到此错误“ MV:无法统计'〜Desktop / RecyclingBin / testtest':没有这样的文件或目录。它确实存在,并且位于〜Desktop / RecyclingBin / testtest位置

fileName=$1
fileLocation='cat ~/Desktop/RecyclingBin/logs/$fileName
if [ -z "$1" ]
   then
       echo "please enter a valid filename"
   else
       echo "do you want to restore?"
   read ans

   if [ "$ans" =="y" ]
   then
       mv "~/Desktop/RecyclingBin/$fileName" "$fileLocation"
   fi
fi

最佳答案

引号防止~的扩展。将其放在引号之外:

mv ~/Desktop/RecyclingBin/"$fileName" "$fileLocation"

关于linux - 无法统计电视,找不到文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27028870/

10-11 16:21