简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM