📜 ⬆️ ⬇️

About different Linux and Unix shells

image Surely almost all Habr readers know the sh and bash shells. Also, most of us have heard something about zsh and tcsh. However, this list of existing shells does not end there. Conditionally, you can divide them into three groups:


About the most interesting of them and will be discussed.

The purpose of writing this article was not to review or classify all existing command shells. I just want to talk about some interesting products in this area, broaden the reader’s outlook. I will be glad. if this leads someone to a more detailed study of the topic, or even to switch to another one.
First, briefly about what it is. A command shell or command interpreter is an application that provides a user with a command line interface in which it either enters commands individually or runs scripts consisting of a list of commands. Oral and informal texts are often referred to as “walking,” from the English shell - the shell.

The most widespread are POSIX-compatible shells, which carry the pedigree from the Bourne shell (Bourne shell), so we’ll start with it
')
Bourne shell and its clones


Bourne shell , executable file: sh . A command shell named after its creator Stephen Born. Most of the operators were borrowed from the Algol 68 language. It was published in the 7th edition of the UNIX operating system, where it was a default shell. Until now, the vast majority of Unix-like systems have / bin / sh - a symbolic or hard link to an sh-compatible shell.

Bourne again shell , executable file: bash . The name can be translated as “Revived Born Walk”. Most likely the most popular shell to date. The de facto standard for Linux. I will not dwell on it, because There are a lot of good bash articles on the internet. For example, here and here .

Z shell , executable file: zsh . Free modern sh-compatible shell. It has a number of advantages over bash related mainly to work online. About her on Habré wrote here and here
In addition, there are quite a few shells falling into this group: Korn shell (ksh) and Almquist shell (ash) etc, but we will not dwell on them in detail.

C shell


C shell , executable file: csh A command shell developed by vi author Bill Joy . The basis for the scripting language csh was taken, as the name implies, the language C. Since at that time, in 1978, it was the most popular programming language among BSD UNIX developers and users. At present, the free implementation of csh - tcsh is more popular.

TENEX C Shell , executable file: tcsh . It was in tcsh that autocompletion appeared for the first time. It is the default wrapper for FreeBSD. Read more about it here .
In order to visually show the difference in syntax, I will give several examples of scripts that do the same for csh and sh-compatible command interpreter.

Conventional design:
#!/bin/sh if [ $days -gt 365 ] then echo This is over a year. fi 
 #!/bin/csh if ( $days > 365 ) then echo This is over a year. endif 


Multiple Branching (Switch, Swich / Case):
 #!/bin/sh for i in d* do case $i in d?) echo $i is short ;; *) echo $i is long ;; esac done 
 #!/bin/csh foreach i ( d* ) switch ( $i ) case d?: echo $i is short breaksw default: echo $i is long endsw end 


The cycle calculates 10 first powers of two:
 #!/bin/sh i=2 j=1 while [ $j -le 10 ]; do echo '2 **' $j = $i i=`expr $i '*' 2` j=`expr $j + 1` done 
 #!/bin/csh set i = 2 set j = 1 while ( $j <= 10 ) echo '2 **' $j = $i @ i *= 2 @ j++ end 


However, the list of features supported by fresh versions of bash, zsh and tcsh is very similar and the choice of a particular shell is mostly a matter of taste. With less common shells, the situation is different. Here the differences are more significant.

Command shells based on popular programming languages.


Perl Shell , executable file: psh . A shell that combines the functions of the above-mentioned shells and the power of Perl. Since psh is written in perl; it can even run on Windows. Some examples of using psh are:
  ls | s/y/k/ #  c    ls | { print ++$i, ": $_"; }q #  .      perl,  $_    . netstat | { $_[1]>2; }g # grep-.           true command >[=FOO] #      command >[2] file #  command 2> file  bash.        grep foo lib/**/*.pm #  **,        


Scsh executable file scsh . The open source command interpreter uses Scheme 48 as the scripting language. It does not support functions standard for other shells (command history, editing text on the command line, adding paths / commands). Writing scripts is recommended, but not for interactive work. Can come to taste lovers of functional programming. Below is an example script that displays the names of all executable files located in directories from the PATH environment variable.
 #!/usr/local/bin/scsh -s !# (define (executables dir) (with-cwd dir (filter file-executable? (directory-files dir #t)))) (define (writeln x) (display x) (newline)) (for-each writeln (append-map executables ((infix-splitter ":") (getenv "PATH")))) 


IPython . This is an interactive shell for the Python programming language, which has a number of additional functions. IPython has a special profile to act as a system command shell. The way to launch this mode depends, as I understand it, on the version, but on my machine it looks like this:
ipython3 --profile=pysh

About IPython has already been written quite a lot, including in Russian (links at the end of the article). I will try to list its main features in terms of using it as a command shell:

As you can see, IPython is at least not inferior to bash in its interactive capabilities. As for scripts, IPython will be convenient for those who know python better than bash. In fact, IPython scripts will differ from pure python only by simplified invoking system commands. Here are some examples of the integration of python and system commands:
 #         dpkg: In [58]: cd /var/log/ /var/log In [59]: log_files = !ls -l dpkg.log* In [60]: log_files[0] Out[60]: '-rw-r--r-- 1 root root 1824 . 3 16:41 dpkg.log' In [61]: for line in log_files: ....: size += int(line.split()[4]) ....: In [62]: size Out[62]: 1330009 # ...      In [67]: for i in range(100,110): ....: !ping -c 1 192.168.0.$i ....: 


Rest

Of course, this is not a complete list of even popular shells. In addition to the above categories, there are still using their own syntax that is not compatible with sh and does not copy existing PL . An example is the friendly interactive shell (fish) . But lastly I would like to tell not about her, but a more specific sleepshell.

Sleep Dummy Shell , executable file: sleepshell . Strictly speaking, the sleepshell command processor cannot be named, since he can't handle commands. And in general, she is not able to do anything except periodically write asterisks "*" to the standard output. However, it is used exactly as a command shell and for this: Suppose we want to give someone the opportunity to make ssh tunnels through our server running Linux or Unix. Read more about ssh-tunneling here . But we do not need at the same time that this someone got access to the command line and the file system of our server. A sleepshell is designed for this case. Create an account on the server as a shell for it, install sleepshell. The account owner will be able to connect and forward ports, but will not be able to execute commands.

That's all. Hope that was interesting. I would welcome any comments and advice on the text of the article.

Related Links

www.faqs.org/faqs/unix-faq/shell/shell-differences - summary table of differences and similarities of command shells
www.mariovaldez.net/software/sleepshell - Sleep Dummy Shell
ipython.org/ipython-doc/dev/interactive/shell.html - IPython as a system shell
www.opennet.ru/base/dev/ipython_sysadmin.txt.html - IPython Shell as a System Administrator Tool
www.focusresearch.com/gregor/document/psh-1.8.1.html - Perl Shell Documentation
www.scsh.net - Scsh home page

Source: https://habr.com/ru/post/157283/


All Articles