0

I wonder why a command that executes commands from a file in the current shell is named source. I can't see a relation between run commands in the current shell and the meaning of the english word source. Is there a history behind that name?

  • 1
    Not english native, but leo translation to german from "to source sth." = "etw. beziehen" is exactly what I understand from what the command does. – pLumo Jul 12 at 13:51
  • 1
    I believe (i.e., always assumed) it is to stand in contrast to invoking a subshell to execute the commands in a file: sh file.sh vs. source file.sh. Emphasizing that the file is taken as the source of input (stdin) for the current shell. – L. Scott Johnson Jul 12 at 13:55
5

A shell’s purpose is to read commands and execute them, whether that’s interactively or from a script. In that context, I’ve always thought of source as specifying the source of the commands the shell should execute (reverting to the current source once it’s finished).

Bill Joy (who introduced source in the C shell) defined the command thus:

The source command causes the shell to read commands from a specified file. It is most useful for reading files such as .cshrc after changing them.

3

From Lexico, the Oxford Dictionary site:

source

VERB [WITH OBJECT]

  1. Obtain from a particular source.

Isn't that exactly what this command is doing? Obtaining variable, alias and function definitions, and other shell settings, from a particular file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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