Reputation: 165
Say I made and compiled a small program in C
to count the bytes of a file, called filebyte
. To run it I would use ./filebyte
Now I want to make it universal on bash, like for example to run a php file, I would use bash
command php file.php
, same way I would like to run my program, filebyte filename
.
How do I do this?
Thanks!
Upvotes: 1
Views: 194
Reputation: 137467
I often create a bin/
directory in my home directory, for small custom applications.
You then need to add that directory to your PATH, which is a list of colon-separated paths that your shell searches for executables when you type a name on thr command line.
This is usually accomplished by putting this in your ~/.bashrc
file:
PATH="$PATH:~/bin"
Upvotes: 3
Reputation: 85790
If you want it for your current active shell alone, do
export PATH=$PATH:</path/to/file>
For permanently making the file available add the above line to ~/.bashrc
Why add it in PATH
variable, man bash
says why,
PATH The search path for commands. It is a colon-separated list of
directories in which the shell looks for commands (see COMMAND
EXECUTION below). A zero-length (null) directory name in the
value of PATH indicates the current directory. A null directory
name may appear as two adjacent colons, or as an initial or
trailing colon. The default path is system-dependent, and is set
by the administrator who installs bash. A common value is
''/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''.
Upvotes: 1
Reputation: 8310
Check the environment variable PATH
and put the executable in one of the directories listed. You can also put it in a custom directory and then append it to PATH
. You can check it by executing printenv PATH
Upvotes: 1