I read "Linux Bible 10th Edition", chapter 3: Using the shell, at 70 page. There is Tip section:
If you want to add your own commands or shell scripts, place them in the bin directory in your home directory (such as /home/cn/bin for the user named cn). This directory is automatically added to your path in some Linux systems, although you may need to create that directory or add it to your PATH on other Linux systems. So, as long as you add the command to your bin with execute permission, you can begin using it by simply typing the command name at your shell prompt. To make commands available to all users, add them to /usr/local/bin
I'm running Fedora Linux 35 Workstation Edition and trying to create my custom command. I've created ~/bin/kek.sh
#! /usr/bin/bash echo "Kek"
and go to the command line, enter
kek in my home directory. I got
bash: kek: command not found.... After that I went to my ~/.bashrc and added following lines at the end of file
PATH=$PATH:~/home/bin/kek; export PATH;
Then returned to ~ directory, entered
kek and got the same
bash: kek: command not found....
I've changed .bashrc PATH line to
PATH=$PATH:~/home/bin; export PATH;, reload terminal session and always getting the same result.
Please, explain, why it didn't work for me? How can I create my own command and make it accessible just by it's name? Thank you.
~refers to your home directory. To add your
binsubdirectory to the path you should use
kek.sh, however you are invoking
kek, in UX style OS's, files are identified by its magic number not by extension, so if you want to call that file there are three steps involved. 1.- Ensure that your PATH environment variable includes the PATH where your executable is located. 2.- Check that your file is executable, at least for the person that is executing (700 ~ rwx------, here read write execute for the owner) 3.- Invoke it with the name that was saved in the filesystem (respect upper and lower case). that surely will do the job.