If you know for sure, that you are using this function only from the command line, you can of course place it into your initialization files.
If you plan to use it from other shell scripts too, you have to ways to go:
You can organize your programming environment around libraries consisting of one or more function definitions, which you source from those shell scripts which need them, or
You drop the idea of using functions and make executable scripts out of it.
As long as your functions are not supposed to manipulate shell variables, it's up to you which way to go. Using a separate, executable script instead of a function, has of course the advantage that it can be executed from any other program, not only from bash.
~/.profile
is to configure your login session, not your shell. Only the login shell reads that file.bash
customisation goes in~/.bashrc
– Stéphane Chazelas Nov 14 '17 at 21:53/home/user/bin
is designed for user scripts. You may add this. – Nov 14 '17 at 22:22$PATH
is built read this. – Nov 14 '17 at 22:26~/bin
has been designated for user scripts, except by recent versions of Ubuntu. – igal Nov 15 '17 at 06:14~/.bashrc
( or any other file for that matter ) ? Manual way only? – Sergiy Kolodyazhnyy Nov 15 '17 at 08:33~/.bashrc
. I wouldn't say that~/.bashrc
is the "manual way" of doing anything, since it's run automatically (under the appropriate conditions). – igal Nov 15 '17 at 13:10~/.bashrc
you could use thetype
ordeclare -f
commands. They will output the function definition. So you could do something likedeclare -f myfunction >> ~/.bashrc
to append the function definition formyfunction
to the~/.bashrc
file. – igal Nov 15 '17 at 13:16