4

While going through many answers on Unix & Linux, I came across many of them writing their contents and tags with POSIX or Bash or some other standard Linux shell.

I know of some differences like some of them have arrays and some do not, and other system level differences which I am not completely aware of.

Question Which one of them is the most widely used? Is there a long term benefit sticking to one over the other?

What are the things that matter for a Bash script writer to begin scripting in another shell?

1
  • Jut one: read the man page for the shell you are using!
    – m4r35n357
    Dec 23, 2023 at 9:25

3 Answers 3

3

Your question is too big to answer in anything but general terms.

POSIX is a family of operating system interface standards; you generally write code / run utilities in a conformant fashion when you want your application to run across a wide variety of Unix-ish systems. As popular as the GNU binutils and bash are, they are not used universally, so sticking to POSIX-conformant functions, flags and utilities can save you some headaches when the time comes to move an app from say Linux to Mac OS.

"Advanced scripting" isn't descriptive enough to recommend a language, but if what you're doing mostly is running programs and using other program to process the results, the shell is the right tool for that. I don't think it matters much which shell you use, since the usual ones are all portable and can be built and installed along with your app. But if you're using data structures beyond one-dimensional arrays, you should be using a language that more easily manipulates such structures, e.g. Perl.

1

Which one of them is the most widely used?

Bash

is the most popular for common tasks not requiring portability.

POSIX

is the only way to make your script portable.


What portability means

It means to be able to run your script on almost any Linux, and alike-platforms such as Cygwin or Android. Though, be aware that it requires some skill to be able to script POSIX-ly. Examples are out of the scope of this Q & A. Feel free to look around U & L.

1
  • 1
    bash can run in POSIX compliant mode "bash --posix" at your bash command prompt will enter this mode. to exit, simply type "bash" again, in your terminal. Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default. (according to the "man bash" description)
    – user12711
    Aug 17, 2019 at 4:34
-1

POSIX is a standard defining how a POSIX-compliant OS (like linux) should behave/work.

As for shell scripting, "sh" was the default command interpreter, nowadays it is usaully a link to another interpreter (bash, ksh...). The core functionnalities of each of them is the same, but each has their specificities (in terms of functionnality, syntax...).

I think, the most widely used is bash, but this is based on my experience.

Not the answer you're looking for? Browse other questions tagged .