Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Guide to Unix/Explanations/Choice of Shell

From Wikibooks, open books for an open world
<Guide to Unix |Explanations

A great variety of shells is available for Unix, including Bourne-compatible shells (sh, bash, ksh, pdksh, ash, dash, etc.), C shell (csh, tcsh), Z shell (zsh), and the Friendly Interactive Shell (fish).

The default interactive shell in many Linux distributions is Bourne-Again Shell (bash). The default script-execution shell in some Linux distribution is Debian Almquist shell (dash). The default shell in macOS used to be Bash as well but is now Z shell (zsh).

Bourne-compatible shells

[edit |edit source]

All Unix shells are similar, but they have different features. If you are beginning, and you are not aware of the differences between shells, then you probably want to start with a Bourne-compatible, POSIX (Portable Operating System Interface)-compatible shell such asbash orksh.

Bourne-compatible shells:

  • sh is the originalBourne shell. On many non-Linux systems, this is an old shell without the POSIX features. Thus bash and ksh (or even csh and tcsh) are better choices than sh. On some systems though, sh is really the same as bash or ksh.
  • bash is theGNU Bourne-again shell. It is mostly Bourne-compatible, mostly POSIX-compatible, and has other useful extensions. It is the default on most Linux systems. If it is not the default, it is probably installed on Linux, and can also be installed on non-Linux systems.
  • ksh is one of the three:
    • Public domain ksh (pdksh) is Bourne-compatible[1] and mostly POSIX-compatible.
    • AT&T ksh was a commercial shell. It has all of the features of pdksh, plus the ksh93 version has several interesting extensions, different from bash. It is licensed under an opensource license since 2005; Mac OS X 10.4 includes it.
    • mksh is the MirBSD enhanced version of the Public Domain Korn shell (pdksh)
  • ash, theAlmquist shell, is a POSIX compliant shell that is much smaller than bash. It is the default shell in multiple BSD variants. Its variantDebian Almquist shell (dash) is the default shell in Debian and Ubuntu Linux distributions for execution of shell scripts as opposed to interactive use.

Links:

C shell

[edit |edit source]

BSD introduced the C shell, which sometimes resembles slightly the C programming language. This shell iscsh. The shelltcsh is csh with more features. These shells are NOT Bourne-compatible. Many of the features were later added to the Bourne-compatible shells (except old copies of sh). When these features work differently in C shell and Bourne-compatible shells, this guide will describe the Bourne-compatible shells.

If csh or tcsh is your default shell, you might benefit by using bash or ksh to get Bourne-compatibility and POSIX features. Some users still prefer the C shell.

Links:

Z shell

[edit |edit source]

There are alternative shells such aszsh, the Z shell. The Z shell boasts extra and unusual features that make it the preferred shell of many (for example, it has a builtin ftp client). Though the Z shell is almost Bourne-compatible, it differs in enough ways that its default behaviour is not Bourne-compatible, though zsh is capable of masquerading as a Bourne shell when so instructed. It can also emulate ksh.

Links:

Temporarily using a different shell

[edit |edit source]

If you do not like the shell that you are using, you might want to use a different shell such asksh orbash. Shells are normal programs, and can be run easily. The SHELL environment variable will still contain the default shell. Theexit command will return you to the first shell.

tcsh>echo $SHELL/bin/tcshtcsh>bashbash$echo $SHELL/bin/tcshbash$exitexittcsh>

Permanently changing the default shell

[edit |edit source]

Find list of shells by looking at/etc/shells (which can be done by executingmore /etc/shells). The commandpasswd -e, on some systemschsh, will prompt for a new shell. To change frombash totcsh one can simply executechsh which will query the user to enter the absolute path to a new shell:

$chshPassword: Changing the login shell for baldurEnter the new value, or press ENTER for the default       Login Shell [/bin/bash]:/bin/tcsh

or the user can specify the shell:

$chsh -s /bin/tcshPassword:

The shell must be specified using its absolute path, which may be found usingwhich tcsh.

Links:

Related books

[edit |edit source]

Reference

[edit |edit source]
  1. pdksh Version 5.2.9http://www.cs.mun.ca/~michael/pdksh/NEWS "can compile as sh again (--enable-shell=sh)."

Links

[edit |edit source]
Retrieved from "https://en.wikibooks.org/w/index.php?title=Guide_to_Unix/Explanations/Choice_of_Shell&oldid=4591900"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp