/ factorpad.com / tech / linux-essentials / source-command.html
An ad-free and cookie-free website.
Intermediate
Learn to read and execute commands at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux source Command Summary with Examples (3:38)
Our eighty-seventh word, or command to memorize is
source
from our category
Workflow.
source
allows you to read and execute
commands from a file.
-options | description |
---|---|
|
None for this command |
Recall from videos (tutorials) #47 and #49 we saw shell built-in programs that modified variables and here we'll learn another shell built-in that reads and executes commands as we transition to our last section on writing scripts to pull together what we've learned here.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The source
command has
no options, and the argument is the file.
Unlike most commands, help is not available with double-dash
--help
and information is found in
the lengthy man
page for
bash
.
So why is source
an important command?
Well, at times you need to run scripts in the current setting without
say logging out and back in to take effect, like a configuration file.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. Start with
mkdir
from video (tutorial) #22 to
create a directory called bin
and put
it in our home directory using the tilde
~/
.
So source
reviews directories in the
PATH, but bin won't be there (meaning typing the name of the
script won't work until you add this directory to your PATH). So you
can add a line export PATH=~/bin:
,
you need the colon, and then this section here for the PATH variable
"$PATH"
to your
.bashrc
file so that
bash
at startup adds this directory
to the PATH each time.
Okay, let's move on the script. I used
nano
to create
funscript
, and at this
point it prints text and the date. We'll add to it in coming videos
(tutorials).
Please pause the video to read and create this on your end and save
it as funscript
.
Okay next, use chmod 700
so the owner
can read, write and execute funscript
.
And last, let's type source funscript
.
And there it is, how fun. 8D
Okay now you know how to use source
.
And you know the syntax for commands, options and arguments.
One last tip about the source
command. So there is a synonym for
source
that you really need to know
and it's simply a period .
. That's it.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the source
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
We'll keep building on this script as we explore the Intermediate-level topic of shell scripting. It may help to supplement this text-based tutorial with our YouTube videos for the more difficult section ahead.
ssh
command, hit
Back.time
command, click Next./ factorpad.com / tech / linux-essentials / source-command.html
A newly-updated free resource. Connect and refer a friend today.