-3

What is extension & execution command for following file formats -

Bourne Shell, Korn Shell, Bourne Again Shell, POXIS shell & TENEX/TOPS C Shell.

Like normal bash file can be created with '.sh' extension & can easily be executed by command - 'shell filename.sh'.

Gaurav
  • 1
  • 2
  • @ilkkachu I am working on a task to automate file execution. I have to automate these file execution, I searched but couldn't get clarity on what are the extension of these file type and execution command. I hope you can help me. – Gaurav Nov 15 '21 at 10:58
  • 3
    A script is executed by the interpreter referred to by the `#!`-line on line 1 of the script (if the file is executable). The filename is unimportant. You should not need to specify an explicit interpreter on the command line at all. I'm uncertain about the context to the question, so I don't know what is actually sought. – Kusalananda Nov 15 '21 at 11:01
  • 3
    Does this answer your question? [Use .sh or .bash extension for bash scripts?](https://unix.stackexchange.com/questions/182882/use-sh-or-bash-extension-for-bash-scripts) (there might be better duplicates) – Kusalananda Nov 15 '21 at 11:05
  • See [this link](https://bash.cyberciti.biz/guide/Shebang) about the `#!`-line also known as 'shebang' line. – sudodus Nov 15 '21 at 11:06
  • Additionally: [Does the shebang determine the shell which runs the script?](https://unix.stackexchange.com/q/87560/108618) – Kamil Maciorowski Nov 15 '21 at 11:13

1 Answers1

3

The extension is completely irrelevant. With very few exceptions (such as gzip), extensions are optional and arbitrary on *nix systems. A shell script doesn't need an extension and any extension it may have carries absolutely no meaning. You could call a bash script foo.asldifjh and it would work in exactly the same way as foo.sh.

So, to answer your question, for all the shells you mentioned, the extension is irrelevant and all of them can launch a script with shellName /path/to/script. All of them can also use a shebang line. Here's one for ksh for example:

#! /bin/ksh

If the script file has a shebang line and is set to executable (chmod a+x /path/to/script), you can simply run /path/to/script directly and the script will be interpreted by whatever shell you have in the shebang line. Again, the extension is completely irrelevant.

terdon
  • 234,489
  • 66
  • 447
  • 667
  • 1
    in particular, not relying on the extension but the `#!` line makes it easier to change the language the script is written in. E.g. if I write a shell script `mytool`, I can later decide to rewrite it in Perl without changing the name. – ilkkachu Nov 15 '21 at 11:58
  • 1
    It may also be worth noting that the pathname mentioned in the `#!`-line depends on where the specific interpreter is installed. There are _common_ pathnames for shells like `sh` and `bash` etc., but thy are not _standard_. Finding `bash` at `/bin/bash` is not guaranteed (but it may be _expected_, at least on Linux systems of today). – Kusalananda Nov 15 '21 at 12:04
  • See also [Why the "-" in the "#! /bin/sh -" shebang?](//unix.stackexchange.com/q/351729) – Stéphane Chazelas Nov 15 '21 at 15:06