Creating terminal commands

I've written a program in C, called count_0.1 which is essentially a word count program.
I want to be able to use it as a command in the terminal (by typing in count), like when you type in ls, you don't have to go to a directory, find an executable and type in: ./ls

I've tried:

  • Adding the line to .bashrc in my home directory: alias count_0.1='count'
  • Putting the count_0.1 file into bin (which made that terminal recognise the command count_0.1, but not count, and if I restarted the terminal, the command no longer worked).
  • Creating a bin folder in my home directory and checking that the path is set there in .profile (in my home directory).

Cheers in advance for any light shed on the issue

Add the following line to .bashrc (assuming count_0.1 is in your home directory)
alias count='~/count_0.1'

To call count_0.1 from bin as count
ln -s ~/count_0.1 /usr/bin/count

For using your $HOME/bin, export it along with other $PATH variables. (Add this line to your .bashrc file to make it available across login.)
export PATH=$PATH:~/bin

1 Like