What is linux scripting language

Which scripting language is the most widely used in Linux?

As we write scripts for Linux systems, there has been a discussion regarding the most universally applicable scripting language for Linux. It’s worth noting that embedded Linux systems may have a simplified BusyBox setup that doesn’t include all POSIX features.

The most universal scripting language for Linux is?

When it comes to Linux systems, there has been a discussion about the most widely used scripting language. Should it be Bash, SH, Posix, or something else?

On every unix-like operating system, there are two programming environments that are Turing-complete and capable of invoking other programs: awk and sh, which is part of the Bourne/POSIX shell family. While awk is focused on text processing and supplements more specialized utilities, sh is designed to assemble programs. Sh serves as the universal scripting language in Linux and across the unix realm.

The features of sh itself and its associated utilities are defined by the POSIX standard. POSIX 1003.1-2004 (also known as Single Unix v3 or the Open Group Base Specification issue 6) is followed by most unix-like systems, with the latest version being POSIX 1003.1-2008 (also known as Single Unix v4 or the Open Group Base Specification Issue 7).

Every Linux and Unix-like system includes a Bourne-style shell located at /bin/sh . Additionally, any non-antique system contains a POSIX-compliant shell (with the exception of occasional bugs). All modern Unix-like systems, including Linux, support shebangs. Therefore, if the first line of a script is #!/bin/sh , it will automatically run in /bin/sh . It is worth noting that in certain POSIX systems, sh may be located elsewhere (typically in emulation layers on OSes that are not typically considered Unix-like).

Embedded Linux systems often feature a simplified BusyBox system, which may lack certain POSIX functionalities. Due to the numerous compile-time options available in BusyBox for accommodating small-footprint systems, it can be challenging to anticipate its specific capabilities. Therefore, script customization is necessary for each device. BusyBox is widely used as a compact implementation of sh and various utilities. Alternatively, you may come across the significantly scaled-down shell environment found in Android, particularly in earlier versions.

Читайте также:  Обновление kali linux через терминал

In non-embedded Linux systems, either dash or bash is commonly used as the /bin/sh . Dash is a compact and speedy shell that primarily supports POSIX features, while bash is a larger shell offering additional features.

Bash is typically found in non-embedded Linux systems, making it portable. It offers various helpful features like arrays, convenient handling of dot files, the ability to obtain the return status of commands in a pipeline using the additional comparison variable, file time operators, and recent versions include regular expression matching.

In shell programming, you not only rely on the sh program but also on various utilities. On Linux, the majority of file manipulation and text processing utilities are the GNU coreutils (on embedded systems, they are typically sourced from BusyBox).

If you require portability beyond Linux, your safest choice is to rely on POSIX. It is possible that other Unix variants may not have bash pre-installed; while bash is included as part of the standard installation on OSX, it is an optional package on *BSD and most commercial Unix systems. However, almost all Unix variants apart from Linux and OSX (such as *BSD and commercial Unix systems) have some version of the Korn shell, like pdksh. Since many of bash’s convenient extensions are derived from ksh, it can be advantageous to write scripts that can run on both shells. Nevertheless, determining the location of bash or ksh on an unknown system can be somewhat challenging.

Although the shell has its limitations, there are two widely used alternatives for more advanced scripting languages: Perl and Python. While Perl has a long-standing reputation as a traditional scripting language and is commonly found on non-embedded Linux systems, Python is gaining popularity, especially as it is recommended for scripting in Ubuntu. Outside of the Linux realm, Perl comes pre-installed on OSX and OpenBSD, and is commonly installed though optional on FreeBSD and NetBSD.

  1. Be quiet, but adhere to POSIX-specified utilities.
  2. When using bash, ensure that you explicitly mention it in the shebang line to avoid getting dash as an alternative.
  3. Python is used by nearly everyone.
  4. Perl. But you get to write it.
Читайте также:  Криптопро linux установка промежуточного сертификата

Following that, the lack of limitations makes it so that there is little that cannot be accomplished with only those.

Typically, I would mention sh , but given your mention of Linux, I will instead refer to bash . This code is present on all Linux systems, with the exception of the exceedingly small and minimalist ones.

In case you are not concerned about non-linux portability, and if you don’t need to run on small distros or embedded Linux devices such as plastic-box routers, you can take advantage of the substantial improvements it provides compared to plain sh . Otherwise, utilize sh .

Following bash (and sh ), the next widely used scripting language for Linux is typically a variation of awk , commonly either mawk or gawk . By utilizing plain awk and avoiding gawkisms, your script should work smoothly on nearly all Linux systems, although it may be absent on smaller distributions or embedded devices. While most Linux systems come with both mawk and gawk pre-installed, certain distributions (such as debian) have mawk as the default, requiring you to manually install gawk if desired.

The next option would be perl . From what I know, the base perl language is pre-installed on all common Linux distros, making it a favorable choice. Fortunately, there is minimal version incompatibility with perl5 releases. However, some obscure features were finally removed in perl 5.12 or maybe 5.14 after being deprecated for about 15 years. These warnings serve as a reminder not to use them. As long as your coding style is not too unusual and you don’t disregard over a decade’s worth of «don’t do that» warnings, your perl scripts will run smoothly on almost any system. Perl is a robust and powerful language that can perform all the tasks of awk and sed , and even more. With a bit of effort, it can also handle tasks that sh is traditionally good at, such as running external commands and using/piping the output. Additionally, the standard perl libraries are quite comprehensive, covering more than just the basics.

Читайте также:  Linux cryptopro csp pfx

One thing to consider about perl is the extensive library of CPAN modules that provide a wide range of functionalities. However, not all of these modules may be available on every perl system. Although they are generally of high quality, it is important to ensure that the necessary modules are installed if you decide to use them. For Linux users, many CPAN modules are pre-packaged, while the remaining ones can be easily installed using the cpan tool. On debian/ubuntu/etc, it is possible to convert a CPAN module into a .deb package using dh-make-perl .

While there are many positive aspects of Python, I cannot confidently say python is one of them. The issue lies in its lack of inclusion as a default on several Linux systems, as well as its problematic version compatibility, both for Python itself and its supposedly «standard» libraries. Some distributions make commendable efforts to address these problems, while others do not. Additionally, Python is primarily a language designed by programmers for programmers, rather than sysadmins, which leads to a disregard for the importance of system integration and an assumption that their code is unique and does not require consideration for existing systems.

Please don’t misinterpret my sarcasm, as I genuinely appreciate python as a programming language. However, I strongly dislike the challenges associated with version and dependency management, which feels like a step back to the past when we had to manually search for obscure code snippets and patches to compile and run programs on proprietary *nix systems.

I recommend using ksh93 or even the POSIX flavor, and you can always use bash/zsh for execution.

Debian-based distros utilize mawk, not gawk, as the default awk. Therefore, it is advisable to refrain from using gawk additions because mawk is considerably faster.

UNIX operating system, UNIX is a powerful Operating System initially developed by Ken Thompson, Dennis Ritchie at AT&T Bell laboratories in 1970. It is prevalent among scientific, …

Источник

Оцените статью
Adblock
detector