What's the meaning of a dot before a command in shell?

Clash Royale CLAN TAG#URR8PPP
up vote
50
down vote
favorite
While following android eclipse debug tutorial, I encounter following commands.
cd /path/to/android/root
. build/envsetup.sh
lunch 1
make
emulator
My problem is what the dot before build/envsetup.sh means?
shell
add a comment |Â
up vote
50
down vote
favorite
While following android eclipse debug tutorial, I encounter following commands.
cd /path/to/android/root
. build/envsetup.sh
lunch 1
make
emulator
My problem is what the dot before build/envsetup.sh means?
shell
add a comment |Â
up vote
50
down vote
favorite
up vote
50
down vote
favorite
While following android eclipse debug tutorial, I encounter following commands.
cd /path/to/android/root
. build/envsetup.sh
lunch 1
make
emulator
My problem is what the dot before build/envsetup.sh means?
shell
While following android eclipse debug tutorial, I encounter following commands.
cd /path/to/android/root
. build/envsetup.sh
lunch 1
make
emulator
My problem is what the dot before build/envsetup.sh means?
shell
shell
edited Feb 9 '14 at 5:18
slmâ¦
241k66500668
241k66500668
asked Feb 9 '14 at 4:49
Jichao
397157
397157
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
58
down vote
accepted
A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.
Example
Say I had the following contents in a sample.sh file.
$ cat sample.sh
echo "hi"
echo "bye?"
Now when I source it:
$ . sample.sh
hi
bye?
$
Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.
Examples
Say I had these commands in another file, addvars.sh.
$ cat addvars.sh
export VAR1="some var1 string"
export VAR2="some var2 string"
Notice that I don't have any variables in my current shell's environment.
$ env | grep VAR
$
Now when I source this file:
$ . addvars.sh
$
OK, doesn't seem like it did anything, but when we check the env variables again:
$ env | grep VAR
VAR1=some var1 string
VAR2=some var2 string
add a comment |Â
up vote
49
down vote
To add to slm's answer:
There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.
For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:
#!/bin/bash
cd ~
cd ..
pwd
So, let's call this script, oh, foo. And let's run this script as follows: ./foo
We will see the following:
/home
(Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")
Now, after running this script, let's type in this command
pwd
To see which directory we are in. We will see something like this:
/home/username
The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.
Now, let's run the foo script like this
. ./foo
Or, equivalently:
source ./foo
If we do a pwd afterwards, we will see this:
/home
The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.
Let me come up with a simpler example. Let's have a script that looks like this:
#!/bin/bash
exit
Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:
./foo
Nothing happens. However, on the other hand, if we do this:
. ./foo
Or this:
source ./foo
We log out.
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
add a comment |Â
up vote
4
down vote
The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
58
down vote
accepted
A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.
Example
Say I had the following contents in a sample.sh file.
$ cat sample.sh
echo "hi"
echo "bye?"
Now when I source it:
$ . sample.sh
hi
bye?
$
Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.
Examples
Say I had these commands in another file, addvars.sh.
$ cat addvars.sh
export VAR1="some var1 string"
export VAR2="some var2 string"
Notice that I don't have any variables in my current shell's environment.
$ env | grep VAR
$
Now when I source this file:
$ . addvars.sh
$
OK, doesn't seem like it did anything, but when we check the env variables again:
$ env | grep VAR
VAR1=some var1 string
VAR2=some var2 string
add a comment |Â
up vote
58
down vote
accepted
A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.
Example
Say I had the following contents in a sample.sh file.
$ cat sample.sh
echo "hi"
echo "bye?"
Now when I source it:
$ . sample.sh
hi
bye?
$
Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.
Examples
Say I had these commands in another file, addvars.sh.
$ cat addvars.sh
export VAR1="some var1 string"
export VAR2="some var2 string"
Notice that I don't have any variables in my current shell's environment.
$ env | grep VAR
$
Now when I source this file:
$ . addvars.sh
$
OK, doesn't seem like it did anything, but when we check the env variables again:
$ env | grep VAR
VAR1=some var1 string
VAR2=some var2 string
add a comment |Â
up vote
58
down vote
accepted
up vote
58
down vote
accepted
A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.
Example
Say I had the following contents in a sample.sh file.
$ cat sample.sh
echo "hi"
echo "bye?"
Now when I source it:
$ . sample.sh
hi
bye?
$
Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.
Examples
Say I had these commands in another file, addvars.sh.
$ cat addvars.sh
export VAR1="some var1 string"
export VAR2="some var2 string"
Notice that I don't have any variables in my current shell's environment.
$ env | grep VAR
$
Now when I source this file:
$ . addvars.sh
$
OK, doesn't seem like it did anything, but when we check the env variables again:
$ env | grep VAR
VAR1=some var1 string
VAR2=some var2 string
A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.
Example
Say I had the following contents in a sample.sh file.
$ cat sample.sh
echo "hi"
echo "bye?"
Now when I source it:
$ . sample.sh
hi
bye?
$
Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.
Examples
Say I had these commands in another file, addvars.sh.
$ cat addvars.sh
export VAR1="some var1 string"
export VAR2="some var2 string"
Notice that I don't have any variables in my current shell's environment.
$ env | grep VAR
$
Now when I source this file:
$ . addvars.sh
$
OK, doesn't seem like it did anything, but when we check the env variables again:
$ env | grep VAR
VAR1=some var1 string
VAR2=some var2 string
edited Aug 13 '15 at 6:30
Slothworks
384316
384316
answered Feb 9 '14 at 5:01
slmâ¦
241k66500668
241k66500668
add a comment |Â
add a comment |Â
up vote
49
down vote
To add to slm's answer:
There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.
For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:
#!/bin/bash
cd ~
cd ..
pwd
So, let's call this script, oh, foo. And let's run this script as follows: ./foo
We will see the following:
/home
(Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")
Now, after running this script, let's type in this command
pwd
To see which directory we are in. We will see something like this:
/home/username
The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.
Now, let's run the foo script like this
. ./foo
Or, equivalently:
source ./foo
If we do a pwd afterwards, we will see this:
/home
The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.
Let me come up with a simpler example. Let's have a script that looks like this:
#!/bin/bash
exit
Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:
./foo
Nothing happens. However, on the other hand, if we do this:
. ./foo
Or this:
source ./foo
We log out.
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
add a comment |Â
up vote
49
down vote
To add to slm's answer:
There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.
For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:
#!/bin/bash
cd ~
cd ..
pwd
So, let's call this script, oh, foo. And let's run this script as follows: ./foo
We will see the following:
/home
(Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")
Now, after running this script, let's type in this command
pwd
To see which directory we are in. We will see something like this:
/home/username
The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.
Now, let's run the foo script like this
. ./foo
Or, equivalently:
source ./foo
If we do a pwd afterwards, we will see this:
/home
The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.
Let me come up with a simpler example. Let's have a script that looks like this:
#!/bin/bash
exit
Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:
./foo
Nothing happens. However, on the other hand, if we do this:
. ./foo
Or this:
source ./foo
We log out.
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
add a comment |Â
up vote
49
down vote
up vote
49
down vote
To add to slm's answer:
There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.
For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:
#!/bin/bash
cd ~
cd ..
pwd
So, let's call this script, oh, foo. And let's run this script as follows: ./foo
We will see the following:
/home
(Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")
Now, after running this script, let's type in this command
pwd
To see which directory we are in. We will see something like this:
/home/username
The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.
Now, let's run the foo script like this
. ./foo
Or, equivalently:
source ./foo
If we do a pwd afterwards, we will see this:
/home
The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.
Let me come up with a simpler example. Let's have a script that looks like this:
#!/bin/bash
exit
Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:
./foo
Nothing happens. However, on the other hand, if we do this:
. ./foo
Or this:
source ./foo
We log out.
To add to slm's answer:
There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.
For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:
#!/bin/bash
cd ~
cd ..
pwd
So, let's call this script, oh, foo. And let's run this script as follows: ./foo
We will see the following:
/home
(Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")
Now, after running this script, let's type in this command
pwd
To see which directory we are in. We will see something like this:
/home/username
The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.
Now, let's run the foo script like this
. ./foo
Or, equivalently:
source ./foo
If we do a pwd afterwards, we will see this:
/home
The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.
Let me come up with a simpler example. Let's have a script that looks like this:
#!/bin/bash
exit
Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:
./foo
Nothing happens. However, on the other hand, if we do this:
. ./foo
Or this:
source ./foo
We log out.
edited May 3 '15 at 13:35
dhag
10.9k32742
10.9k32742
answered Feb 9 '14 at 5:45
samiam
2,346713
2,346713
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
add a comment |Â
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
2
2
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
Your answer is better than the accepted one, I understood how you explained, thanks!
â Ahmed
Jul 25 '16 at 13:03
add a comment |Â
up vote
4
down vote
The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.
add a comment |Â
up vote
4
down vote
The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.
The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.
edited 13 mins ago
Andrii Abramov
1033
1033
answered May 3 '15 at 13:44
tlund
33518
33518
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f114300%2fwhats-the-meaning-of-a-dot-before-a-command-in-shell%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password