Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've correctly added my scripts folder to my $PATH. But I still cannot run the scripts from anywhere by simply calling them. How do I achieve this?

Example. If I have ~/scripts/ in my path and in ~/scripts/ I have foo.sh I want to be able to be anywhere and type foo and have it execute foo.sh. When I type echo $PATH I see my scripts folder correctly included in my path. I've also made foo.sh executable because if I cd to the scripts directory and type foo.sh it runs correctly.

What am I missing?

share|improve this question

migrated from stackoverflow.com Apr 1 '13 at 18:34

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 2 down vote accepted

If you type in "foo.sh", you'll likely start your script up since the path to it is now included in your "$PATH" file.

Right now the shell simply doesn't know how to map "foo" to "foo.sh".

So maybe you just need to add an alias to your .tcshrc / .bashrc (e.g. "alias foo foo.sh") or an actual file symlink (e.g. "ln -s foo foo.sh") to your script and you'll be all set.

share|improve this answer
    
or just remove the .sh extension its not actually necessary –  prodigitalson Apr 1 '13 at 15:19
    
OK. So if I type foo.sh from anywhere it works but simply foo doesn't work. Prodigitalson how do you get it so you don't need to specify the file extension? –  Jesse Atkinson Apr 1 '13 at 15:22
    
I offered you two possible solutions, Jesse. Which one seems more straightforward to you? –  Michael Dautermann Apr 1 '13 at 15:24
    
It appears the only way to achieve what I want without declaring the file extension is to also set a symlink or an alias. –  Jesse Atkinson Apr 1 '13 at 16:22
    
@JesseAtkinson I suspect you're coming from a Windows background, where you don't need to type the .exe part to run foo.exe, and Windows "knows" that files with certain extensions are executable. It does this because earlier versions of Windows did not have a file permissions/executable bit like OSX/Unix/Linux. Now that you're using OSX (which is BSD Unix under the hood), you'll just need to get used to the different system. You can name a file whatever you want, and as long as you set the X bit you can run it, but you need to enter its full name. –  MattDMo Apr 1 '13 at 19:33
show 1 more comment

From your description, it should work, except for the part where you seem to want to alias foo to foo.sh. Did you re-source your .profile, .bashrc, or wherever you made the change to PATH afterward? Next you can add an alias from foo foo.sh.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.