1

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...

3
  • So zsh doesn't seem to expand ~ in variables. I'm sure this is a recurring problem, where did you look for solutions already? – nohillside Nov 5 '20 at 15:18
  • Ok, thanks for the hint, found this: stackoverflow.com/questions/56951712/… – rjrunner44 Nov 5 '20 at 15:21
  • moving ~ out of string quote fixed it, e.g. export $ZSH=~"/.oh-my-zsh" Thanks for pointing me in right direction – rjrunner44 Nov 5 '20 at 15:23
3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .