Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:14:02+00:00 2026-05-30T02:14:02+00:00

In my .bash_profile I have the following lines: PATHDIRS= /usr/local/mysql/bin /usr/local/share/python /opt/local/bin /opt/local/sbin $HOME/bin

  • 0

In my .bash_profile I have the following lines:

PATHDIRS="
/usr/local/mysql/bin
/usr/local/share/python
/opt/local/bin
/opt/local/sbin
$HOME/bin"
for dir in $PATHDIRS
do
    if [ -d $dir ]; then
        export PATH=$PATH:$dir
    fi
done

However I tried copying this to my .zshrc, and the $PATH is not being set.

First I put echo statements inside the “if directory exists” function and I found that the if statement was evaluating to false, even for directories that clearly existed.

Then I removed the directory-exists check, and the $PATH was being set incorrectly like this:

/usr/bin:/bin:/usr/sbin:/sbin:
/usr/local/bin
/opt/local/bin
/opt/local/sbin
/Volumes/Xshare/kburke/bin
/usr/local/Cellar/ruby/1.9.2-p290/bin
/Users/kevin/.gem/ruby/1.8/bin
/Users/kevin/bin

None of the programs in the bottom directories were being found or executed.
What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:14:03+00:00Added an answer on May 30, 2026 at 2:14 am

    Unlike other shells, zsh does not perform word splitting or globbing after variable substitution. Thus $PATHDIRS expands to a single string containing exactly the value of the variable, and not to a list of strings containing each separate whitespace-delimited piece of the value.

    Using an array is the best way to express this (not only in zsh, but also in ksh and bash).

    pathdirs=(
        /usr/local/mysql/bin
        …
        ~/bin
    )
    for dir in $pathdirs; do
        if [ -d $dir ]; then
            path+=$dir
        fi
    done
    

    Since you probably aren’t going to refer to pathdirs later, you might as well write it inline:

    for dir in \
      /usr/local/mysql/bin \
      … \
      ~/bin
    ; do
      if [[ -d $dir ]]; then path+=$dir; fi
    done
    

    There’s even a shorter way to express this: add all the directories you like to the path array, then select the ones that exist.

    path+=/usr/local/mysql/bin
    …
    path=($^path(N))
    

    The N glob qualifier selects only the matches that exist. Add the -/ to the qualifier list (i.e. (-/N) or (N-/)) if you’re worried that one of the elements may be something other than a directory or a symbolic link to one (e.g. a broken symlink). The ^ parameter expansion flag ensures that the glob qualifier applies to each array element separately.

    You can also use the N qualifier to add an element only if it exists. Note that you need globbing to happen, so path+=/usr/local/mysql/bin(N) wouldn’t work.

    path+=(/usr/local/bin/mysql/bin(N-/))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script mysql_cron.sh that runs mysqldump #!/bin/bash /usr/local/mysql/bin/mysqldump -ujoe -ppassword >
In .bash_profile I have listed many env variables as follows: export JAVA_HOME=... export PYTHON=...
I have the following line in a shell script: source bash_profile It does not
I have the following in my .bashrc file: # Git Bash Completion source $HOME/.git_completion
I added some settings to .bash_profile and closing/opening terminal doesn't seem to have the
I've installed rails, the mysql2 gem, and mysql and have created a project called
I have locally installed a newer version of Python. For that I did the
I am running Mac OS X 10.5.8. I have installed Python 2.6 from the
I have two versions of python installed on my mac running OSX Lion. The
Using [[ -s $HOME/.rvm/scripts/rvm ]] && . $HOME/.rvm/scripts/rvm in .bash_profile. OSX Lion In order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.