weird ZSH issue (resolving environment variable)

using ZSH mac latest. In .zshrc I have:

export ZSH="~/.oh-my-zsh"

that directory exists:

cd ~/.oh-my-zsh
me@Imac-Retina-2 .oh-my-zsh % ls
CODE_OF_CONDUCT.md  README.md           lib/                oh-my-zsh.sh-SAVED  themes/
CONTRIBUTING.md     cache/              log/                plugins/            tools/
LICENSE.txt         custom/             oh-my-zsh.sh        templates/

but trying to resolve $ZSH fails:

cd ~
ls $ZSH
ls: ~/.oh-my-zsh: No such file or directory
cd $ZSH
cd: no such file or directory: ~/.oh-my-zsh

it's not related to the particular $ZSH variable. For example, I can define export PDQ="~/Downloads" and cd $PDQ fails (no such file or directory), but cd ~/Downloads works just fine.

I have NO CLUE...anyone? 🤷‍♂️

This seems to be only related to the filesystem, other environment vars work and resolve just fine in apps, etc...


As explained in https://stackoverflow.com/questions/56951712/why-is-zsh-not-able-to-read-tilde-from-a-path-in-a-script zsh doesn't expand ~ within double quotes. So you can do one of

export ZSH=~"/.oh-my-zsh"
export ZSH="$HOME/.oh-my-zsh"

(where the second option also works if there are space characters in your home path), or set

set -o magicequalsubst

to have zsh expand ~ in such cases.