Running a Shell script from the current directory without "./filename"

I created a file called "testfile" and made it executable with chmod +x testfile. To execute the testfile, I need to run the command ./testfile.

I need to know if there is a way to run the program without using ./and execute the file with the command testfile?

Below is a simple code inside the "testfile" file

echo Todays date is : 
date
+5
source share
3 answers

You can execute it without. / using:

sh testfile

or

sh /path/to/file/testfile

Edit
If you want to execute a program directly using a command, then you can define an alias:

alias execute_testfile="sh /path/to/file/testfile"

And then you will execute the program whenever you write

execute_testfile

, .

, alias ... ~/.profile ~/.bash_profile.

+4

. PATH :

> echo 'echo Hello, World!' > mycommand
> mycommand
-bash: mycommand: command not found
> ./mycommand
Hello, World!
> PATH=".:$PATH";
> mycommand
Hello, World!
>
+2

PATH .profile, .

vi ~/.profile

.profile

/path/to/dir/:$PATH

"add/path/to/dir/ PATH"

PATH , :

vi /etc/environment - edit, save your changes
source /etc/environment
echo $PATH - should now return your new PATH

Ubuntu, Debian, , /etc/environment PATH -

-

vi ~/.bashrc

alias <your_script> ='/path/to/your_script.sh'

, - . /.sh

+2
source

All Articles