Bash shell comes with source command which is used to read and execute commands from given FILENAME and return. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed. This is useful to create your own shell scripting libraries and call them using the source command. The syntax is as follows:
source /path/to/fileName
Create a shell script called functions.sh as follows:#!/bin/bashNow create a file called test.sh:
JAIL=/jaildir
addusertojail(){
echo "Adding users..."
}
setupjail(){
echo "Setting up jail"
}
#!/bin/bash
source functions.sh
# access $JAIL defined in functions.sh
echo "Jail dir : $JAIL"
# call functions
addusertojail
setupjail
No comments:
Post a Comment