Execute a shell script without `./` [duplicate]

I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript. Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.

I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.


Solution 1:

To run scripts you have written yourself you have a couple options.

OPTION 1

You can store them in /usr/bin.

This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise

I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin

OPTION 2

You can just store them all in your testing folder so in my case...

Documents/SourceCode/

and add this to my path variable.

export PATH=$(PATH):/home/user/Documents/SourceCode