Why is zsh not able to read ~ (tilde) from a path in a script? Why is zsh not able to read ~ (tilde) from a path in a script? shell shell

Why is zsh not able to read ~ (tilde) from a path in a script?


Use the following code to get what you want:

export PATH=~/Desktop/Capture/echo $PATH# Result:    /Users/swift/Desktop/Capture/

Although, when you're using a string, you'll get this:

export PATH="~/Desktop/Capture/"echo $PATH                      # Result:    ~/Desktop/Capture/

So to get it right, you'll have to try this approach:

tilde=~export PATH="${tilde}/Desktop/Capture/"echo $PATH                             # Result:    /Users/swift/Desktop/Capture/

P.S. Also, there's one useful command for tilde to be expanded.

Here's an example:

echo tilda=~# Result:    tilda=~

Use magicequalsubst command in zsh:

set -o magicequalsubstecho tilda=~    # Result:    tilda=/Users/swift