Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I keep my common shell scripts in /usr/share/bash, and use this script to "include" the ones I want:
Code:
$ cat /usr/share/bash/include
#!/bin/bash
# Define the function to include all the programs listed in "$*" from /usr/share/bash
#
# Usage: include function1 {function2 ...}
#
# Note: This function assumes that any function to be included may be an executable script
# and searches $PATH for any match before looking in the location array entries.
#
# Define the include function if it's not already defined
if [ "$(type -t include)" != "function" ]
then
include ()
{
local d f abort loc found
local -a locations
# This is the array naming the locations to be searched
locations=("/usr/share/bash" "${HOME}/Scripts/Bash")
abort=0
for f in "$@"
do
loc=$(type -P "${f}")
if [ -z "${loc}" ]
then
found=0
for d in "${locations[@]}"
do
if [ -f "${d}/${f}" ]
then
. "${d}/${f}"
found=1
break
fi
done
if [[ ${found} == 0 ]]
then
echo Error: The bash include file \"${f}"\" could not be found." > /dev/stderr
abort=$((++abort))
fi
else
. "${loc}"
fi
done
[ ${abort} -gt 0 ] && exit ${abort}
}
fi
Here's an example of how I use it:
Code:
# Load the local function definitions
. /usr/share/bash/include
include define_colors \
sucmd \
connect_using_nmcli_to \
vg_activate \
mount_noauto \
mount_cifs \
mount_iso
For a resource of solutions to low-level shell scripting problems in Linux, see linux-shell-base. It provides solutions for multiple aspects of the Linux application layer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.