シェル
シェル は、ユーザにテキストベースのインターフェースを提供する、コマンドラインインタプリタです。 仮想コンソール 内の (または、シリアル接続を介した 端末エミュレータ 内の) コマンドラインインターフェースとして、またはリモートシェルとして (例えば SSH を介して)、さらには スクリプト インタプリタとして (あらかじめ書かれたコマンドを実行することによって)、使用することができます。
Most shells can interpret shell scripts : text files that contain prewritten commands targeting a specific shell or set of compatible shells.
Shells can often be accessed remotely, over SSH for example, or over a serial connection, etc.
典型的には、シェルはユーザが端末でログインした後に開始する最初のプログラムです。 /etc/passwd ファイルは、システム上のユーザごとの ログインシェル を定義する情報を含んでいます。ログイン後は、ユーザは端末から他のシェルを起動したり、ログインシェルを変更したり、特定の端末エミュレータの下で使用するシェルを指定したりすることができます。
A user can switch their current session to any other available shell simply by typing the command to run the alternative shell. It is usually possible to set the choice of login shell, in case of specific requirements or user preference (see "User's login shell" section below). Certain terminal emulators allow defining a specific shell for use in that emulator.
Gentoo では、 /bin/sh ファイルはデフォルトシステムシェルへのシンボリックリンクになっているため、複数の異なる POSIX シェルから 1 つ選んでリンクすることができます。 ハンドブック に従ってインストールした後は、デフォルトのシェルは bash になっているでしょう。
For information about scripting in the context of POSIX and different shell implementations, refer to the Shell/Scripting page.
日常的な使用のためのヒントについては 端末エミュレータ の記事も参照してください。
スクリプトを書くときには、最初の行で シバン を使うことによって、正しいインタプリタを参照することに注意を払うできです。例えば、
#!/bin/sh
で始まるスクリプトは bash 特有のコードを一切含めずに、POSIX の構成要素のみを使用するべきです。
コマンドラインインターフェース
Unix 系 の コマンドラインインターフェース (CLI) は、現代的なコンピュータとやり取りするための、強力で成熟したパラダイムです。CLI はグラフィックベースのモデルに対していくつかの特筆すべき強みを維持していて、そのため多くのプロフェッショナルに選ばれるツールとなっています。
CLI は一般的に 端末エミュレータ (または 仮想コンソール ) 内で実行するシェルを通してアクセスされる、標準化されたテキストベースのインターフェースを提供します。
CLI には、 CRT スクリーン技術よりもさらに昔の テレタイプ端末 に始まる、豊かな歴史があります。この長い歴史により洗練されたシステムが生み出され、 UNIX OS とともにその特性の多くを発展させてきました。今日では、テキストはほとんど常にキーボードで入力され、出力はスクリーンに提示されます。
学習曲線は GUI のそれよりも険しいかもしれませんが、最小限のスキルを一度身に付ければ、CLI は、システム上で利用可能なすべてのコマンドをユーザの指先一つで利用できるように提供します。メニューを読んだり遷移する必要はありません。
CLI ツールは、オプションを組み合わせて期待する機能を達成できるように、シンプルで覚えやすいインターフェースを提供する傾向にあります。CLI は一般的に、ツール間の緊密な連携を可能にするために標準的なインターフェースに従います。また、
man ページ
を利用して、あるいはより手軽には
--help
を利用して、ツールのマニュアルへのアクセスも可能にしています。
現代的なシェルは パイプ などの強力なしくみが利用でき、さまざまなツールがこれを利用してシームレスに連携することができます。さらに、複数の CLI ユーティリティ を利用して、出力のフィルタリングとソートを行うことも可能です。
CLI ユーティリティには、実行後に基本的な入力を求めたり、そのコマンドに固有のサブシェルを開いたりするような、対話的なものもあります。多くのユーティリティはコマンドライン、 標準入力 、ファイル、デバイス、またはネットワークから入力を受け取ります。そして、コマンドラインに出力するか、そうでなければ出力をファイルにリダイレクトしたり、他のコマンドにパイプしたりすることができます。
利用可能なソフトウェア
Gentoo はシェルの選択肢を提供しています:
POSIX シェル
| 名前 | パッケージ | ホームページ | 説明 |
|---|---|---|---|
| ash | sys-apps/busybox | https://www.busybox.net/ | BusyBox's uses the minimalist Almquist shell. |
| bash | app-shells/bash | https://tiswww.case.edu/php/chet/bash/bashtop.html | B ourne A gain Sh ell は Gentoo のデフォルトのシェルです。Gentoo のデフォルトパッケージマネージャである Portage によって使用されています。 |
| dash | app-shells/dash | http://gondor.apana.org.au/~herbert/dash/ | D ebian A lmquist Sh ell。小さく高速で posix 準拠の、( /bin/sh の置き換えとして) スタートアップスクリプトに適したシェルです。 |
| dsh | app-shells/dsh | https://www.netfort.gr.jp/ | A shell distributed shell that enables parallel execution of commands across large numbers of servers. |
| ksh | app-shells/ksh | http://www.kornshell.com/ | オリジナルの Korn Shell の 1993 リビジョン (ksh93) です。 |
| mksh | app-shells/mksh | https://www.mirbsd.org/mksh.htm | 活発に開発されている Korn Shell の自由な実装で、スクリプティングによく適しています。 |
| pwsh | app-shells/pwsh | https://learn.microsoft.com/powershell/ | 多くのシェルは「すべてはファイルである」と仮定します。PowerShell は「すべてはオブジェクトである」と仮定する、オブジェクト指向のシェルです。今は MIT ライセンスが付与されており、Linux 上で利用可能です。 |
| tcsh | app-shells/tcsh | http://www.tcsh.org/ | Berkeley C Sh ell ( csh ) の改良版。 |
| yash | app-shells/yash | https://yash.osdn.jp/ | Y et A nother SH ell は C99 (ISO/IEC 9899:1999) で書かれた POSIX 準拠のコマンドラインシェルです。 |
| zsh | app-shells/zsh | http://www.zsh.org/ | 多くのユーザにインタラクティブシェルとして選ばれている、高度なシェルです。 |
非 POSIX シェル
Application Compatibility Shells
| Name | Package | Homepage | Description |
|---|---|---|---|
| fish | app-shells/fish | https://fishshell.com/ | The F riendly I nteractive SH ell. |
| cmd.exe | virtual/wine | https://www.winehq.org/ | A shell that reproduces the Microsoft Windows execution environment, part of Wine . |
| command.com | app-emulation/dosemu | http://www.dosemu.org/ | A shell that reproduces the MS-DOS execution environment, part of DOSEMU . |
| AmigaShell | app-emulation/fs-uae | https://fs-uae.net/ | FS-UAE, an Amiga emulator, can be configured to allow shell access from the terminal. The requisite AmigaOS components have open source implementations via AROS . |
Bootloader Shells
| Name | Package | Homepage | Description |
|---|---|---|---|
| GRUB | sys-boot/grub | https://www.gnu.org/software/grub/ | A minimalist pre-boot rescue shell. |
Firmware Shells
| Name | Package | Homepage | Description |
|---|---|---|---|
| Open Firmware | — | https://www.openfirmware.info/ | A Forth -based shell. |
| UEFI | — | https://uefi.org/ | A minimalist firmware shell for EFI firmware. |
さらなるシェルの選択肢については、 app-shells パッケージカテゴリか、次のコマンドの出力を確認してください ( eix が必要です):
user
$
eix -cC app-shells
設定
環境をセットアップする方法については ログイン の記事も参照してください。
システムシェル
/bin/sh を bash 以外のものに変更すると、例えば
#!/bin/sh
で始まるのに bash 特有のコードを使用しているような、よくない書き方をされているスクリプトでまれに問題が起こることがあります。
bug #526268
を参照してください。システムシェルはデフォルトの bash のままにしておき、ユーザの作成時に、または既存ユーザに対しては
chsh
コマンドを使用して、ユーザのログインシェルを設定するのが安全かもしれません -
次の節
を参照してください。
It's normal that only a handful of POSIX compatible shells will be available to be used with this method. See the next section on how to set user login shells, which allows setting more shells as default. Also note the above warning, and consider preferentially using the method from the next section to set any shell as default.
The "system shell" is used when executed from
/bin/sh
, such as by scripts that start with
#! /bin/sh
. Changing the "system shell" will not change what shell users login to, and will not change what shell is set for new users either.
システム管理者は app-alternatives/sh の USE フラグを使用して、システムシェルを変更することができます。このユーティリティパッケージは、 /bin/sh を別の POSIX 準拠シェルへのシンボリックリンクで置き換えることによって、システムのシェルを変更します。
USE flags for app-alternatives/sh /bin/sh (POSIX shell) symlink
/bin/sh の特定の選択を設定するには、 /etc/portage/package.use を使用してください:
/etc/portage/package.use
# /bin/sh を app-shells/dash にある dash へのシンボリックリンクにする
app-alternatives/sh -bash dash
ユーザのログインシェル
fish などの一部のシェルは、ログインシェルとして直接設定すると問題が発生する場合があります。安全にデフォルトシェルとして設定する方法については、 fish 記事の caveats 節 を参照してください。
ログインシェルの設定は /etc/passwd に保存されます。
ログインシェルを指定してユーザを作成する
Login shells can be set when creating a new user with the useradd command (from sys-apps/shadow ).
To create a user and specify their login shell:
user
$
useradd -s /bin/ksh -m larry
The
-s
option indicates the path to the shell, the
-m
option instructs the
useradd
command to create the new user's home directory if it does not already exist.
既存ユーザのログインシェルを設定する
ユーザのログインシェルは chsh コマンドを使用して変更することができます。現在のユーザのログインシェルを変更するには、 chsh を入力して、新しいシェルへのパスを入力してください。下の例では、 larry という名前のユーザが、自身のログインシェルを /bin/ksh から /bin/zsh に変更しようとしています:
user
$
chsh
larry のログインシェルを変更中 新しい値を入力してください。標準設定値を使うならリターンを押してください ログインシェル [/bin/ksh]: /bin/zsh
chsh は、任意のユーザのログインシェルを変更するために、スーパーユーザアカウント (root) から使用することもできます。
The chsh command only allows shells listed in /etc/shells .
トラブルシューティング
表示が文字化けしている
条件によっては、シェルの出力が文字化けすることがあります。これを修復するための手順については 端末エミュレータ の記事を参照してください。
関連項目
- GNU Coreutils — provide many of the basic commands of the UNIX(like) OS.
- Login — logging in to a shell, and setting up the default environment.
- Recommended tools — lists system-administration related tools recommended for use in a shell environment ( terminal/console )
- Terminal emulator — ビデオ端末を別のディスプレイアーキテクチャの中で (例えば X の中で) エミュレートします。
- util-linux — contains userspace utilities for Linux-specific system management, including device control, terminal logins, process management, and tty messaging.