1

I have a custom command called git-feature, which is located in a Unix executable file with the same name. I'm trying to configure the $PATH variable in ~/.bash_profile so that it recognizes the Unix file. I updated the PATH variable to include the file's path:

export PATH=$PATH:~/Applications/MAMP/htdocs/code/git-shortcuts/ 

The echo $PATH command in my bash terminal produces the following result:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/myname/Applications/MAMP/htdocs/code/git-shortcuts/ 

But trying to call git-feature leads to the following error:

-bash: git-feature: command not found 

There are a few similar questions on S.O., but none of the ones I found solved this specific type of issue. Do I need to change the PATH variable differently in order for my custom command to be recognized by bash?

4
  • 1
    Did you add execute permissions with chmod +x git-feature? Commented Feb 20, 2014 at 15:59
  • 1
    What happens if you run: /Users/myname/Applications/MAMP/htdocs/code/git-shortcuts/git-feature? Is it found and executable? If not, then you've got the wrong directory on your path. If so, there isn't an obvious reason why it would fail. Commented Feb 20, 2014 at 15:59
  • 1
    You need to re-read your profile after changing its contents by logging out and back in or doing ". ~/.bash_profile" Commented Feb 20, 2014 at 16:03
  • 1
    If its custom executable you added to PATH variable, then whether running which git-feature prints ~/Applications/MAMP/htdocs/code/git-shortcuts/git-feature or do you see /usr/bin/which: no somep in (path..... ) ?? Commented Feb 20, 2014 at 16:23

1 Answer 1

1

You are modifying the PATH variable correctly.

Make sure that git-feature really is in that directory, that it has the executable bit (+x) set, and that the directories leading to it give you rights to execute it:

MYFILE=/Users/myname/Applications/MAMP/htdocs/code/git-shortcuts/git-feature ls -l "$MYFILE" chmod +x "$MYFILE" [ -x "$MYFILE" ] && echo "File can't be executed, check directory rights" 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your feedback. I'm still having a little trouble, though. When I add your code to my .bash_profile, I get the following error: "-bash: MYFILE: command not found" I don't know why MYFILE is being treated as a function rather than a variable.
You don't need to run this from .bash_profile, this is a one-time setup - it will add the executable bit and show you whether the command is executable, none of which needs to be run at every login.
About your error, make sure you don't have spaces around the = sign, otherwise it will try to execute MYFILE instead of assigning a value to it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.