-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

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
  • 242,166
  • 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