I have a directory called projects and inside that directory are subdirectories called project1, project2, project3, and so forth. My professor hands out a .sh file located in these numbered subdirectories to test our program, but it doesn't work unless I export the path of these subdirectories to my $PATH.

It seems I have to add export PATH="$PATH:/Users/My_Name/desktop/projects/project1" to get the shell script to work, but that seems to defeat the purpose of $PATH to streamline work on the terminal because I would have to manually go in and add a new path every time I work on a new project.

For example when I work on project 2, I would have to manually go into $PATH and add export PATH="$PATH:/Users/My_Name/desktop/projects/project2" which is tedious because I would have to do this for all future projects.

I have tried to add PATH="$PATH:/Users/My_Name/desktop/projects" to $PATH, but that is not executing the script in the subdirectories of my directory called projects.

Any help is greatly appreciated.

1 Answer 1


The best way in your case is to cd to the projects directory that you are looking at and run the shell command from there.

executables can be run from the PATH as you have tried but also it you give the path to them.

So for project1

cd /Users/My_Name/desktop/projects/project1

then run the script using a path


or use the shell directly

sh scriptname.sh

If you are being taught the teacher should have good reasons to believe you already know this or they should have provide a book or other notes to describe how unix shells work.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .