Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

shell

admin

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
like image 857
Chamara Keragala Avatar asked Feb 18 '13 09:02

Chamara Keragala


People also ask

What is $? == 0 in shell script?

$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.


1 Answers

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.

like image 174
fedorqui 'SO stop harming' Avatar answered Sep 23 '22 08:09

fedorqui 'SO stop harming'