zsh is not Recognizing an Environmental Variable - No such File or Directory - Unix - MacOs

Viewed 520

Expected behavior

List the documents in a directory using an environmental variable.

Steps to Reproduce

INPUT
$ export ICLOUD_D="~/Library/Mobile\ Documents/com~apple~CloudDocs/"
$ source ~/.zshrc
$ echo $ICLOUD_D
$ ls $ICLOUD_D
OUTPUT
$ ~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ ls: ~/Library/Mobile\ Documents/com~apple~CloudDocs/: No such file or directory

Current behavior

Shell gives me a: No such file or directory error.

Steps Performed Thus Far to Fix

If I were to simply cut and paste the file path with the command ls then I'm able to list the files as expected.

I've also tried to put quotes around the environmental variable as well.

$ ls "$ICLOUD_D"

System information - OS: MacOS v 10.15 - Shell: zsh

1 Answers

Do not put quotes around the environmental variable

INPUT

$ export ICLOUD_D=~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ source ~/.zshrc
$ echo $ICLOUD_D
$ ls $ICLOUD_D

OUTPUT

$ ~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ afile
$ bfile
$ ...
Related