1

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
isethi
  • 661
  • 1
  • 10
  • 22

1 Answers1

1

~ 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"
John Kugelman
  • 349,597
  • 67
  • 533
  • 578