Advanced

Bash Shebang

Posted by linuxize on · 2 comments
Linuxize.com
Mail this story
Print this story

If you are learning Bash scripting by reading other people’s code you might have noticed that the first line in the scripts starts with the #! characters and the path to the Bash interpreter. This sequence of characters (#!) is called shebang and is used to tell the operating system which interpreter to use to parse the rest of the file.



Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: GNU, Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (2)

> Interpreter is the full path to a binary file (ex: /bin/sh, /bin/bash).

...Or to anything capable of interpreting the file's contents. I've set up executable RC-files for text conversion where the shebang line calls out a Perl script I wrote, and the process works just fine: the RCfile's shebang line, "#!/usr/local/bin/splitmake" (plus args, including a self-reference) invokes splitmake, a script with a shebang line of "#!/usr/bin/perl -w", and the script's args get passed to the Perl interpreter just fine. The one tricky part I found is that, as noted, "splitmake" needs a commandline-option specifying the name of the RCfile it's supposed to read in and use.

That's just with messing around because I wanted to see if it would work, in the time it took to bring this project up. Somebody with some serious time to kill might discover how to get that calling program's path/name passed; maybe it's in the ENV.
that is interesting. could you share some examples?

i assume you already checked args[0] (or whatever the equivalent is in perl) and its value is "splitmake" and not the name of the script calling splitmake?

if that's the case then i suspect that the value is replaced in the chain of processing these scripts because i would have expected the name from the commandline script to be there, just like in a regular script the value is the name of the script and not of the interpreter.

greetings, eMBee.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post