0

I created a couple of custom bash scripts that does some simple things like starting and stopping a PostgresSQL server. I have them stored in a specific directory of my choice.

Joes-MacBook-Pro:scripts joe$ l
total 24
-rwxr-xr-x  1 joe  staff   124B Apr 18 21:22 pgstart
-rwxr-xr-x  1 joe  staff   114B Apr 18 21:23 pgstatus
-rwxr-xr-x  1 joe  staff   123B Apr 18 21:22 pgstop
Joes-MacBook-Pro:scripts joe$ pwd
/Users/joe/Softwares/scripts

I have even referenced these scripts in my .bash_profile as:

# Custom Scripts
export SCRIPTS_HOME=/Users/joe/Softwares/scripts

Now when I tried to use it as:

Joes-MacBook-Pro:~ postgres$ pgstart
-bash: pgstart: command not found

Should I place this script in the /bin/ directory on my Mac? Any clues?

5
  • Do the scripts have a proper #!/bin/bash as the first line? Do they work when you type /Users/joe/Softwares/scripts/pgstart rather than just pgstart? Commented Apr 18, 2016 at 20:16
  • They work when I specify the full path, but fail when calling using just the script! Commented Apr 18, 2016 at 20:24
  • You need to man bash and learn about PATH. Commented Apr 18, 2016 at 20:25
  • I've added this to the PATH as well! Anyway, I will take a look! Commented Apr 18, 2016 at 20:27
  • May I know why this question was down voted? Commented Apr 19, 2016 at 10:05

3 Answers 3

1

I am no Mac-Expert, but based on linux, it should suffice to do the following in your .bash_profile:

export SCRIPTS_HOME=/Users/joe/Softwares/scripts
export PATH=$PATH:$SCRIPTS_HOME

You could omit the first line, and replace it accordingly.

Don't forget to restart your terminal, or to source your .bash_profile

Sign up to request clarification or add additional context in comments.

9 Comments

I think it has got something to do with user permissions. The scripts have joe as the user, but I'm trying to run this script as the postgres user. Any clues as to how I could make this script visible to the postgres user? Should I change the owner from joe to postgres?
This would be one possibility. Other would be to maybe change the group to postgres. Something like this: chown joe:postgres your_script_path
Should I chown to postgres the entire path that contains the script?
Important is the ownership of the file. So cd into the respective folder and write chown joe:postgres *, or, within the parent folder chown -R joe:postgres folder_name, if you want the folder to get the ownership too.
He has the scripts set as o+rx, so it's not the permissions on the files, but it could be that the directory is unreachable by the other user-- but then they wouldn't work with an absolute path per another comment. It's the PATH setting that is wrong.
|
0

Add this to your ~/.bash_profile:

PATH=$PATH:/Users/joe/Softwares/scripts

Restart Terminal and it will work.

Comments

0

run source ~/.bash_profile to engage the export.

However, prior to that add: PATH=$PATH:$SCRIPTS_HOME to your bash_profile so your executable can be found via command line.

1 Comment

Yes, I have it in the path as well but even then it would not work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.