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
You can execute it without ./ by using:
Or
Edit
If you want to execute the program directly with a command, what you can do is to define an alias:
And then, you will execute the program whenever you write
or whatever name you define.
To make this alias persistent, do include the
alias ...
line in your ~/.profile or ~/.bash_profile files.You need to add
.
to yourPATH
variable like this:You can define PATH variable in .profile file which you can find under your home directory.
Add to the end of your .profile
Which translates to "add /path/to/dir/ to whatever the PATH variable is set"
If you want to add a directory to the PATH for all users of the system you can:
Works on Ubuntu server, I would guess on all Debian distributions, I am not sure if other distributions have /etc/environment or if PATH is specified somewhere else
Aliasing is still a better solution
Add to the end of the file
Log out, log back in - you shouldnt have to type ./.sh anymore'