What is the use of UNIX source command under bash or any other shell? How do I use source command under UNIX / OS X / Linux operating systems?
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/fileNameCreate a shell script called functions.sh as follows:
#!/bin/bash JAIL=/jaildir addusertojail(){ echo "Adding users..." } setupjail(){ echo "Setting up jail" }
Now create a file called test.sh:
#!/bin/bash source functions.sh # access $JAIL defined in functions.sh echo "Jail dir : $JAIL" # call functions addusertojail setupjail
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop










![Linux: HowTo Copy a Folder [ Command Line Option ]](http://s13.cyberciti.org/images/shared/rp/3/8.jpg)


{ 3 comments… read them below or add one }
Thanks,
This if for the first time , I have herd about source command..
very informative post :)
hi, ‘source’ it’s similar to ‘.’.
‘.’ is a synonym for ‘source’
Good Explanation….