I need to be able to remove a directory that is relative to the Documents folder of any user's system.
rmdir: ~/Documents/Folder: No such file or directory
If I manually enter the expanded path (/Users/ricky/Documents/Folder), it works fine.
I thought bash automatically expanded the tilde at the beginning of paths?
Update:
After trying a bunch of different approaches as recommended, I'm pretty confident now that the issue is with how I'm storing the path. I'm getting the path from a text file which I read line by line:
...
export_folder_path="$(echo $line | cut -f2 -d=)"
...
echo $export_folder_path
rmdir $export_folder_path
rmdir "$HOME/Documents/Folder\ 1"
This outputs the following:
$HOME/Documents/Folder\ 1
rmdir: $HOME/Documents/Folder\ 1: No such file or directory
rmdir: /Users/ricky/Documents/Folder\ 1: Directory not empty (This is actually what I want)
I can't work out what the difference between my manually typing the export path and using the variable. Why is the variable refusing to expand $HOME
? I have tried many variations of adding quotations with no luck.
Tilde expansion doesn't work in all cases. You can instead use the
HOME
variable:From bash manual: