bluepinto bluepinto - 3 months ago 6
Linux Question

How to make my Linux C program accessible from bash

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!

Answer

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"
Comments