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
  • 557
  • 1
  • 6
  • 16

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
  • 307,513
  • 65
  • 473
  • 519