Any way to avoid dot-slash when running executable scripts in bash?

let's say I have a script.

chmod +x myscript

Now to run this I go

./myscript

But is there any way I could just run it by typing

myscript

???


Solution 1:

I had same issue and seems no answer till now answers to the question clearly.

The solution to the question is to add export PATH=.:$PATH to your .bash_profile. This will include the current directory to the unix search path while it searches for the command. It is also wise to have yourself informed about the security risks of doing so.

Solution 2:

add the path of the directory where your script is located to the PATH variable:

export PATH=$PATH:/path/to/directory

Solution 3:

create symbolic link of script file in any /bin/ , /usr/bin etc.

ln -s /path_to_script/myscript /usr/bin/myscript 

Solution 4:

export PATH=/path_to_folder_containing_executable/:$PATH

If you don't want to run that every time you open a new terminal, you could always add that line into your ~/.bashrc.

Good luck!