-3

I have a question about a shell interpreter, though I have used it for many years.

At the beginning of a shell, we always setup the environment, followed by our shells. Below are two examples:

File 1:

#!/usr/bin/env bash 
 "bash shells"

File 2:

#!/usr/bin/env jruby 
 "ruby shells"

Do the above two samples mean that the interpreter of both scripts is created at the beginning and then both interpreters execute the following scripts, "Bash shells" and "Ruby shells"?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
shijie xu
  • 1,975
  • 21
  • 52
  • What do you mean by "bash shells" and "ruby shells"? Why are you referring to the code in the script as a "shell"? Are your two bash/ruby examples meant to be in the same file or in two separate files? – BrenBarn Oct 13 '14 at 19:34
  • Of course there are in two separated files. – shijie xu Oct 13 '14 at 19:35
  • The sheband need not be "an interpreter". For example using `#!/bin/cat` will output the contents of the file to the terminal and using `tac` instead of `cat` will output them reversed. – Bakuriu Oct 13 '14 at 19:39
  • This appears to have nothing to do with Ruby or Python, only bash shell. – the Tin Man Oct 13 '14 at 22:46

2 Answers2

1

From Wikipedia:

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script. For example, if a script is named with the path path/to/script, and it starts with the following line:

#!/bin/sh

then the program loader is instructed to run the program /bin/sh instead (usually this is the Bourne shell or a compatible shell), passing path/to/script as the first argument.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
Alexander
  • 12,424
  • 5
  • 59
  • 76
0

That line is called a shebang line.

These two pages have more information that you will likely ever care to know about this.

http://www.in-ulm.de/~mascheck/various/shebang/

http://homepages.cwi.nl/~aeb/std/hashexclam-1.html

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148