4

I am writing a script and I want it to start with the Bourne shell. As I understand it, starting the script with:

#! /bin/sh

will not always specify the Bourne shell, but whatever the OS links to /bin/sh. Is there a way to explicitly specify Bourne?

Thanks!

Josh
  • 113
  • 9
  • 4
    Are you meaning something like '#!/bin/bash'? See [here](http://stackoverflow.com/questions/8967902/why-do-you-need-to-put-bin-bash-at-the-beginning-of-a-script-file) – Paolo Gibellini Oct 05 '15 at 10:40
  • 1
    Thanks for your comment, but I actually specifically do not want Bash. I need to use the Bourne shell specifically. – Josh Oct 05 '15 at 10:43
  • 1
    well, that changes system to system, as you said in your question, so you have to change it in your script as well, most of time its pointing to `bash` – Amey Jadiye Oct 05 '15 at 11:04
  • 1
    So there is no way I can force bourne instead of bash if `#!/bin/sh` on my system points to bash? – Josh Oct 05 '15 at 11:07
  • 1
    @JoshuaStevenson PaoloGibellini is right. This is citation: "... The Bourne shell was developed in 1977 by Stephen Bourne at AT&T's Bell Labs in 1977. It was the default shell of Unix Version 7. Most Unix-like systems contain the file /bin/sh which is either the Bourne shell, or a symbolic link (or hard link) to a compatible shell...Use of the Bourne Shell has largely been suerceded by the Bourne-Again Shell (bash), which supports more user-friendly interactive features such as job control and a command history..." from http://www.computerhope.com/unix/ush.htm – ryuichiro Oct 05 '15 at 11:12
  • 2
    The hashbang is always a specific path; you can't specify a shell in general. – chepner Oct 05 '15 at 13:23
  • No it's not possible because the information base is over run with people who are lying about which shell to use. They believe they are free software aficionados -- but in fact they are ruining free software and introducing bugs. bash developers and programmers specifically do this –  Oct 05 '15 at 14:37

3 Answers3

5

The original Bourne Shell is not open source, so if you don't already have it, you're SOL.

If you do already have it, just put the location in the shebang.

Simple as that.

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • You mean like `#!/bin/bourne`? – R4F6 Oct 14 '15 at 18:14
  • 1
    @R4F6 - yeah, if you actually do have the bourne shell **(which you don't, i'll tell you right now)** and it's located at `/bin/bourne` then yes, that would work. but since i'm clairvoyant and already know **you don't have it**, no that won't work. – I wrestled a bear once. Oct 14 '15 at 18:21
3

<Reminisce_mode_on>

Place a colon (:) on the first line. I used it on older systems (A/UX, SCO Unix, Interactive Unix System V Release 3.2 SVR3, circa 1989, comes to mind) as the first character in a file to denote a Bourne Shell script. It was also recognised by Thompson Toolkit's Korn Shell (DOS > v3.2 ). Allowed Unix programmers to shell program in the PC environment (DOS/WindowsNT).

</Reminisce_mode_off> Yeah, I'm old. Unix programmers never die, they just become zombie processes.

pacal683
  • 31
  • 1
2

Depends on what you mean by "Bourne Shell".

  1. Original Bourne Shell, which I believe is not what you are after:

    • proprietary, very limited, and only available on some true UNIX systems, such as Solaris, derived from the original AT&T UNIX code.
    • #!/bin/sh is the way to get this non-portable shell.
    • Its ability to run true legacy scripts, and its smallness, are about the only assets it has in my mind. Today's memory gives the size asset less appeal.
  2. Modern shells based on Bourne shell syntax. As opposed to, say csh.

    • bash, ksh, zsh are some. Bash is common in Linux environments, and yes, /bin/sh tends to link to one of these.

    • To use a specific shell, use something like which $SHELL to get an absolute path.

    • #!/bin/env bash is less dependent on the shuffling of paths found in different operating systems.

      But this portable trick has the risk of choosing the wrong shell if PATH is not set well enough and does not allow arguments, such as -x, on the shell.

      It has the advantage of PATH being able to control which of several shells you use if different versions of the same shell are available, which ksh is well noted for.

So, if you want more help you will really need to detail the application you are after, and your definition of "Bourne Shell".

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Gilbert
  • 3,740
  • 17
  • 19
  • "`#!/bin/sh` is the way to get this non-portable shell." -- in systems that have one as `/bin/sh`. Most modern unix-likes probably don't, but have some newer POSIX sh compatible shell there instead. – ilkkachu Mar 02 '21 at 10:13