Does the $dir have to be the absolute path because bash is saying that ~/Desktop doesn't exist
#!/bin/bash
dir="~/Desktop/"
ls $dir
the error is:
ls: ~/Desktop/: No such file or directory
~
isn't expanded when quoted. Leave out the quotes in the assignment.
On the other hand, it's a good idea to quote variable expansions to prevent unwanted globbing and word splitting: "$dir"
> $dir
.
dir=~/Desktop/
ls "$dir"