Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does !# (reversed shebang) means?

Tags:

bash

scala

From this link: http://scala.epfl.ch/documentation/getting-started.html

#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld extends App {
  println("Hello, world!")
}
HelloWorld.main(args)

I know that $0 is for the script name, and $@ for all argument passed to the execution, but what does !# means (google bash "!#" symbols seems to show no result)?

does it mean exit from script and stdin comes from remaining lines?

like image 848
Kokizzu Avatar asked May 08 '14 02:05

Kokizzu


People also ask

What does the fox say Meaning?

Speaking of the meaning of the song, Vegard characterizes it as coming from "a genuine wonder of what the fox says, because we didn't know". Although interpreted by some commentators as a reference to the furry fandom, the brothers have stated they did not know about its existence when producing "The Fox".

What is this song Google?

Ask Google Assistant to name a song On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.

What does the fox say for real?

One of the most common fox vocalizations is a raspy bark. Scientists believe foxes use this barking sound to identify themselves and communicate with other foxes. Another eerie fox vocalization is a type of high-pitched howl that's almost like a scream.


2 Answers

This is part of scala itself, not bash. Note what's happening: the exec command replaces the process with scala, which then reads the file given as "$0", i.e., the bash script file itself. Scala ignores the part between #! and !# and interprets the rest of the text as the scala program. They chose the "reverse shebang" as an appropriate counterpart to the shebang.

To see what I mean about exec replacing the process, try this simple script:

#!/bin/sh
exec ls
echo hello

It will not print "hello" since the process will be replaced by the ls process when exec is executed.

Reference: http://www.scala-lang.org/files/archive/nightly/docs-2.10.2/manual/html/scala.html

like image 90
ooga Avatar answered Sep 20 '22 04:09

ooga


A side comment, consider multiline script,

#!/bin/sh
        SOURCE="$LIB1/app.jar:$LIB2/app2.jar"
        exec scala -classpath $SOURCE -savecompiled "$0" "$@"
!#

Also note -savecompiled which can speed up reexecutions notably.

like image 34
elm Avatar answered Sep 18 '22 04:09

elm