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?
Asked
Active
Viewed 188 times
1
Stephen Kitt
- 411,918
- 54
- 1,065
- 1,164
rrd
- 145
- 4
-
1Not english native, but [leo translation to german](https://dict.leo.org/englisch-deutsch/source) from "to source sth." = "etw. beziehen" is exactly what I understand from what the command does. – pLumo Jul 12 '19 at 13:51
-
1I 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 '19 at 13:55
2 Answers
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.
Stephen Kitt
- 411,918
- 54
- 1,065
- 1,164
4
From Lexico, the Oxford Dictionary site:
source
VERB [WITH OBJECT]
- 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?
muru
- 69,900
- 13
- 192
- 292