Executing Shell Script from current directory without '"./filename"

admin, linux, shell

Solution

You can execute it without ./ by using:

sh testfile

Or

sh /path/to/file/testfile

Edit If you want to execute the program directly with a command, what you can do is to define an alias:

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

And then, you will execute the program whenever you write

execute_testfile

or whatever name you define.

To make this alias persistent, do include the `alias ...` line in your ~/.profile or ~/.bash_profile files.

Problem

I have created a file called "testfile" and made it executable using `chmod +x testfile`. In order to execute the file "testfile" i need to run the command `./testfile`. I need to know is there any way i could run the program without using `./` and execute the file using `testfile` command? Shown below is a simple code inside the file "testfile" ``` echo Todays date is : date ```

Original source