Tags:
create new tag
, view all tags
"Sourcing" a file is an alternate way of running it.

Here's an example:

$ ./name_of_script # executing a script $ . ./name_of_script # sourcing a script

The most significant difference is that:

  • If you execute a script, you start a new shell with a new environment, etc. When the script is done, you return to the shell and environment that existed before you executed the script. If you changed the environment (added to the path) in the script, it has no effect after the script is run.
  • If you source a script, you run the commands in the file in the current environment. If you change the environment in a sourced file the change stays in effect after the script is sourced.

In addition:

  • If you source a file, it doesn't need the shebang line (#!)

From man bash (using /source (that's a search for "source")):

<quote>

source filename [arguments]: Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain a slash, file names in PATH are used to find the directory containing filename. The file searched for in PATH need not be exe­cutable. When bash is not in posix mode, the current direc­tory is searched if no file is found in PATH. If the sou­cepath option to the shopt builtin command is turned off, the PATH is not searched. If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged. The return status is the status of the last command exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read.
</quote>

See AboutThesePages.

<Currently, no significant content below this line.>

Contents

Notes

Resources

See ResourceRecommendations. Feel free to add additional resources to these lists, but please follow the guidelines on ResourceRecommendations including ResourceRecommendations#Guidelines_for_Rating_Resources.

Recommended

  • (rhk) [[][]] --

Recommended for Specific Needs

  • (rhk) [[][]] --

Recommended by Others

  • (rhk) [[][]] --

No Recommendation

  • (rhk) [[][]] --

Not Recommended

  • (rhk) [[][]] --

Contributors

  • () RandyKramer - 08 Jul 2002
  • <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>

[[Main.RandyKramer#08 Jul 2002][]]

Rants (Ignore)

See MyRantings.

Page Ratings

Topic revision: r1 - 2002-07-08 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look