0

I found a weird issue, getting different results with and without double quotes on a variable.

$ cat test.sh

#!/usr/bin/env bash 

folder="~/backup"

ls -l ~/backup
ls -l ${folder}

$ bash test.sh
total 197904
-rw-r--r--  1 test  staff  96133120 31 Mar 22:46 backup-202103312246.tar.gz
ls: ~/backup: No such file or directory

If I remove the double quotes from the value of folder

$ cat test.sh
folder=~/backup

ls -l ~/backup
ls -l ${folder}

$ bash test.sh
total 197904
-rw-r--r--  1 test  staff  96133120 31 Mar 22:46 backup-202103312246.tar.gz
total 197904
-rw-r--r--  1 test  staff  96133120 31 Mar 22:46 backup-202103312246.tar.gz

Why do I get the different results?

0stone0
  • 34,288
  • 4
  • 39
  • 64
Bill
  • 2,494
  • 5
  • 26
  • 61
  • Does this answer your question? [Why is a tilde in a path not expanded in a shell script?](https://stackoverflow.com/questions/32276909/why-is-a-tilde-in-a-path-not-expanded-in-a-shell-script) – 0stone0 Mar 31 '21 at 12:07
  • Does this answer your question? [How Can I Expand A Tilde ~ As Part Of A Variable?](https://unix.stackexchange.com/questions/399407/how-can-i-expand-a-tilde-as-part-of-a-variable) – 0stone0 Mar 31 '21 at 12:08

0 Answers0