Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do I fix "cd:1: = not found" in zsh?

Following the instructions here, I have switched the default shell to zsh. But now, the `cd` command is broken. No matter what I enter (e.g., `cd /` or `cd ..`), I get "cd:1: = not found". How do I fix this?

MacBook Pro 13", macOS 10.15

Posted on Dec 2, 2019 1:47 PM

Reply
11 replies

Dec 3, 2019 6:23 AM in response to glsp

Here are some zsh functions that allow you to 1) return the path of the original file or folder given the respective Finder alias on the command line, and 2) a cd function that changes directory into the original, given the alias.


In your ~/.zshenv file:


a2o () {
    # Return original file path given Finder alias
    # Finder alias must be specified as filename.ext\ alias
    f="$1"
    osascript <<-EOF
    use scripting additions

    try
        tell application "Finder"
            set p to "$f" as POSIX file as alias
            return POSIX path of ((p's original item) as text)
        end tell
    on error errmsg number errnbr
        if errnbr = -1700 then
            log "Original file or folder" & return
        end if
    end try
    return
EOF
}

acd () {
# change directory to original folder from Finder folder alias
# Finder alias must be specified as filename.ext\ alias, "filename.ext alias"
orig=$(a2o "$1")
# print ${orig}
[[ -d ${orig} ]] && cd ${orig}
}


This file is read when you first login to a zsh shell, and automatically makes the functions available to the command-line. In the following, I made a Finder alias to the apple.pdf document and stuffed the alias into a Test folder, or made an alias to a Desktop Test folder:


a2o ~/Desktop/Test/apple.pdf\ alias
/Users/$USERNAME/Desktop/apple.pdf

a2o ~/Desktop/apple.pdf
Original file or folder

acd ~/Desktop/Test\ alias
odin3: ~/Desktop/Test %

cd
acd ~/Desktop/Test
Original file or folder
odin3: ~ %



How do I fix "cd:1: = not found" in zsh?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.