Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

As the question says, what is the difference between executing a script with source command and with . , i.e.:

source /some/script

and

. /some/script
share|improve this question

2 Answers 2

up vote 41 down vote accepted

source and . are synonymous in bash.

Update 9-5-2012

There seems to be much disbelief about this! For anyone who might like to verify that the commands are simply synonyms and nothing more: first download and extract the source code. Then examine the file, builtins/source.def. You will read that both of the built-in commands, source and ., use the very same function: source_builtin. The original question was, "What is the difference between source and . in BASH."

share|improve this answer
    
where is this defined? I mean is . an alias for source or is this some thing else? –  binW Feb 9 '11 at 18:26
    
exact same thing –  user8290 Feb 9 '11 at 18:42
6  
@binW: . is the traditional source command, inherited from the ancient bourne shell. source is just a bash builtin that does exactly the same as ., presumably because it's more readable (a . alone may be hard to spot with a small font). You'll see help source and help . shows the same info. –  geirha Feb 9 '11 at 23:56
2  
@binW: If you look in man bash and then search for source you'll see that source filename [arguments] is a synonym for . filename [arguments]. –  Matthew Rankin Feb 17 '11 at 12:22
    
This actually contradicts what I see in this question: askubuntu.com/questions/182012/… –  ysap Aug 30 '12 at 1:09

. is synonymous with source in bash, but not in POSIX sh, so you should use . if your script is run by /bin/sh. Note that bash claims to run like POSIX sh when called as /bin/sh, but accepts source without complaint.

This behaviour has bitten me, scripts tested with bash as /bin/sh fail when run under ash, for example.

share|improve this answer
2  
POSIX does not restrict the shell. POSIX just says; the shell shall support at least this and that feature. So a POSIX shell is free to implement additional features as long as the ones described by POSIX are implemented. When the shebang says #!/bin/sh you should never assume the shell supports anything but POSIX features though. pubs.opengroup.org/onlinepubs/9699919799/utilities/… –  geirha Feb 9 '11 at 23:51
    
You may be affected by the order of looking names up: unix.stackexchange.com/q/17815/8250 –  Lekensteyn Jul 16 '12 at 11:05
    
This answer helped me, since sh is often used in cron. –  dfrankow Mar 8 '13 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.