I have one script with common functions that is included in other my scripts with:
. ~/bin/fns
Since my ~/bin
path is on the PATH, is there a way to prevent users to execute fns
from command line (by returning from the script with a message), but to allow other scripts to include this file?
(Bash >= 4)
Just add the pidof line at the top of your Bash script, and you'll be sure that only one instance of your script can be running at a time.
If you are executing a Bash script in your terminal and need to stop it before it exits on its own, you can use the Ctrl + C combination on your keyboard.
Silencing Output To silence the output of a command, we redirect either stdout or stderr — or both — to /dev/null. To select which stream to redirect, we need to provide the FD number to the redirection operator.
Just remove the executable bit with chmod -x . ~/bin/fns
. It will still work when sourced, but you can't call it (accidentally) by its name anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With