tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec -b file batch mode, read and execute commands from `file' -c command run `command' from next argument -d load directory stack from `~/.cshdirs' -Dname[=value] define environment variable `name' to `value' (DomainOS only) -e exit on any error -f start faster by ignoring the start-up file -F use fork() instead of vfork() when spawning (ConvexOS only) -i interactive, even when input is not from a terminal -l act as a login shell, must be the only option specified -m load the start-up file, whether or not owned by effective user -n file no execute mode, just check syntax of the following `file' -q accept SIGQUIT for running under a debugger -s read commands from standard input -t read one line from standard input -v echo commands after history substitution -V like -v but including commands read from the start-up file -x echo commands immediately before execution -X like -x but including commands read from the start-up file --help print this message and exit --version print the version shell variable and exit See the tcsh(1) manual page for detailed information.
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec -b file batch mode, read and execute commands from `file' -c command run `command' from next argument -d load directory stack from `~/.cshdirs' -Dname[=value] define environment variable `name' to `value' (DomainOS only) -e exit on any error -f start faster by ignoring the start-up file -F use fork() instead of vfork() when spawning (ConvexOS only) -i interactive, even when input is not from a terminal -l act as a login shell, must be the only option specified -m load the start-up file, whether or not owned by effective user -n file no execute mode, just check syntax of the following `file' -q accept SIGQUIT for running under a debugger -s read commands from standard input -t read one line from standard input -v echo commands after history substitution -V like -v but including commands read from the start-up file -x echo commands immediately before execution -X like -x but including commands read from the start-up file --help print this message and exit --version print the version shell variable and exit See the tcsh(1) manual page for detailed information.
TCSH(1) TCSH(1)
名称
tcsh - ファイル名補完とコマンド行編集を追加した C シェル
書式
tcsh [-bcdefFimnqstvVxX] [-Dname[=value]] [arg ...]
tcsh -l
解説
tcsh は、バークレイ版 UNIX の C シェル csh(1) と完全に互換性があり、さ
らに機能強化したシェルです。対話的なログインシェル、またシェルスクリ プ
ト のコマンドプロセッサの両方の用途で使われるコマンドインタプリタです。
tcsh には、コマンド行編集 (コマンド行編集の項を参照)、プログラム可能 な
単 語の補完 (補完と一覧の項を参照)、スペル訂正 (スペル訂正の項を参照)、
履歴 (ヒストリ置換の項を参照)、ジョブ制御 (ジョブの項を参照)、 C 言語風
の 文法があります。新機能の章では、csh(1) には存在しない、tcsh の主な追
加機能について説明しています。このマニュアルを通じ、tcsh の機能のうち、
csh(1) のほとんどの実装 (特に 4.4BSD の csh) にない機能について、ラベル
(+) をつけてあります。そして、csh(1) にあったけれども文書化されていなか
った機能にラベル (u) をつけてあります。
引数リスト処理
シェルへの 1 番目の引数 (引数 0 番) が ‘-’ の場合、シェルはログインシェ
ルになります。シェルを -l フラグを指定して起動することでもログインシ ェ
ルにできます。
残りのフラグは以下のように解釈されます。
-b このフラグは、オプションの処理を強制的に中断させる場合に使用します
。このフラグ以降の引数はすべて、オプションではないものとして処理 さ
れ ます。これにより、混乱を避け、小細工をしなくても、シェルスクリプ
トにオプションを渡すことが可能になります。 set-user ID スクリプトは
本オプションなしでは実行できません。
-c コマンドを、本フラグの次にくる引数 (この引数は省略できません。また
、1 つだけである必要があります) から読み込み、実行します。この引 数
は、あとで参照できるように、シェル変数 command に格納されます。残り
の引数は、シェル変数 argv に代入されます。
-d ログインシェルであるかどうかにかかわらず、スタートアップとシャッ ト
ダ ウンの項で解説されているように ~/.cshdirs から、ディレクトリスタ
ックを読み込みます。(+)
-Dname[=value]
環境変数 name に値 value を設定します。(Domain/OS のみ) (+)
-e 起動したコマンドが異常終了したり、0 でない終了ステータスを返した と
きに、ただちにシェルを終了します。
-f ~/.tcshrc を読み込まずに無視するので、起動が高速になります。
-F プ ロ セ ス を 生成する際に vfork(2) の代わりに fork(2) を使います
。(Convex/OS のみ) (+)
-i たとえ端末上で実行されていなくても、対話的に動作し最上位レベルの 入
力 の際にプロンプトを表示します。入力と出力がともに端末である場合、
本オプションなしでもシェルは対話的に動作します。
-l ログインシェルとなります (-l が、指定された唯一のフラグである場合に
のみ有効です)。
-m 実効ユーザに属していなくても ~/.tcshrc をロードします。新しいバージ
ョンの su(1) は -m をシェルに渡すことができます。(+)
-n コマンドの解析は行いますが、実行はしません。シェルスクリプトのデ バ
ッグに役立ちます。
-q SIGQUIT (シグナル処理の項を参照) を受け付けるようにし、デバッガのも
とで使われても作動するようになります。ジョブ制御は無効にな り ま す
。(u)
-s 標準入力からコマンドを読み込みます。
-t 入 力から 1 行だけ読み込み、それを実行します。入力行の改行の直前に
‘\’ を置くことで、次の行への継続を行うことができます。
-v シェル変数 verbose を設定します。これにより、ヒストリ置換された状態
のコマンド行を表示するようになります。
-x シェル変数 echo を設定します。これにより、実行直前に、実行するコマ
ンドを表示するようになります。
-V ~/.tcshrc を実行する前に、シェル変数 verbose を設定します。
-X ~/.tcshrc を実行する前に、シェル変数 echo を設定します。
-X に対する -x の関係は、-V に対する -v の関係に相当します。
フラグ引数の処理のあと、もし引数が残っていて、かつ、 -c, -i, -s, -t の
い ずれのフラグも指定されていなければ、残っている引数のうち最初のものは
コマンドファイル、つまり「スクリプト」の名前とみなされます。シェルは こ
のファイルをオープンし、‘$0’ による置換に備えてファイル名を保存します。
多くのシステムは、スクリプトが本シェルと互換性のない version 6 ま た は
version 7 の標準のシェルを使っているため、スクリプトの先頭の文字が ‘#’
でない場合、つまりスクリプトがコメントから始まらない場合、本シェルは そ
れらの「標準」のシェルを起動して実行します。
残りの引数はシェル変数 argv に設定されます。
スタートアップとシャットダウン
ロ グ イ ン シ ェ ル の 場 合 は 、実行開始に際し、まずシステムファイル
/etc/csh.cshrc と /etc/csh.login を読み込んで実行します。そしてシェルを
起 動したユーザのホームディレクトリの中から、まずはじめに ~/.tcshrc (+)
を読み込んで実行します。もし、~/.tcshrc が見つからない場合は 、~/.cshrc
を読み込んで実行します。次に、~/.history (もしくは、シェル変数 histfile
の値) を、その次に ~/.login を、最後に、~/.cshdirs (もしくは、シェル 変
数 dirsfile の値) (+) を読み込んで実行します。コンパイルの仕方によって
、シェルは /etc/csh.cshrc の後ではなく前に /etc/csh.login を読み込み 、
~/.tcshrc (または ~/.cshrc) と ~/.history の後ではなく前に ~/.login を
読み込む場合があります。シェル変数 version を参照してください。(+)
ログインシェルでない場合は、/etc/csh.cshrc と 、 ~/.tcshrc ( ま た は
~/.cshrc) のみを起動時に読み込みます。
スタートアップファイルの例は、 http://tcshrc.sourceforge.net を見てくだ
さい。
stty(1) や tset(1) のようなコマンドは、ログインするごとに 1 度だけ実 行
さ れる必要がありますが、これらのコマンドは、普通は ~/.login ファイルに
入れます。 csh(1) と tcsh の両方で同じファイルのセットを使う必要があ る
ユ ーザは、~/.cshrc だけを使い、その中でシェル変数 tcsh (値は任意) があ
るかどうかチェックしてから、tcsh 特有のコマンドを使うようにします。また
は、 ~/.cshrc と ~/.tcshrc の両方を使うが、~/.tcshrc で、 source コマン
ド (組み込みコマンドの項を参照) を使い ~/.cshrc を読み込むようにしま す
。 以 下 、 このマニュアルの残りの部分で ‘~/.tcshrc’ と表現したときは、
「~/.tcshrc、または ~/.tcshrc が見つからない場合は ~/.cshrc」という意味
で使います。
通 常、シェルはプロンプト ‘> ’ を表示し、端末からコマンドの読み込みを開
始します (引数処理と、コマンドスクリプトを含むファイルの処理のための シ
ェルの使用については、後で説明します)。シェルは、入力されたコマンド行の
読み込み、読み込んだコマンド行を単語に分解、およびコマンド履歴への格 納
、 コマンド行の解析、コマンド行の中のコマンドそれぞれの実行を繰り返しま
す。
ログアウトするには、空の行で ‘^D’ とタイプするか、‘logout’ す る か 、
‘login’ するか、シェルの自動ログアウト機構 (シェル変数 autologout を参
照) を使います。ログインシェルが実行終了する際には、ログアウトの状況 に
応 じ て シ ェ ル 変 数 logout を ‘normal’ か ‘automatic’ に設定し、
/etc/csh.logout ファイルと ~/.logout ファイルにあるコマンドを実行します
。コンパイルの仕方によっては、シェルは、ログアウト時に DTR を落とすこと
があります。これについてはシェル変数 version を参照してください。
システムのログインファイル名、ログアウトファイル名は、異なる csh(1) 間
で の互換性を保つために、システムごとにファイルが違います。これについて
は、関連ファイルを参照してください。
編集
はじめに、コマンド行エディタについて説明します。補完と一覧と、スペル 訂
正の 2 つの機能は、編集コマンドとして実装されていますが、特に分けて説明
する必要があるため、項を改めて説明します。最後に、編集コマンドの項で 、
シ ェルに特有の編集コマンドについて、一覧をあげ、デフォルトのバインドと
ともに説明します。
コマンド行編集 (+)
コマンド行の入力データは、GNU Emacs や vi(1) で使われているものと、よく
似 たキーシーケンスを使って編集できます。シェル変数 edit がセットされて
いるときのみ、編集できるようになっています。対話的なシェルでは、この 値
はデフォルトで設定されています。組み込みコマンド bindkey で、キーバイン
ドを変更したり、表示したりできます。デフォルトでは、Emacs 形式のキー バ
イ ンドが使われています (違う方法でコンパイルしなければそうなります。シ
ェル変数 version を参照)。しかし、コマンド bindkey で、キーバイン ド を
vi 形式に一括して変更できます。
シェルは、つねに矢印キー (環境変数 TERMCAP で定義されたものです) を、次
のように割り付けています。
下矢印 down-history
上矢印 up-history
左矢印 backward-char
右矢印 forward-char
他の 1 文字バインドによって、変わっていなければこのようになります。この
よ うなバインドにしたくない場合、settc を使って、矢印キーのエスケープシ
ーケンスを空の文字列にセットすることができます。 ANSI/VT100 の矢印キ ー
シーケンスは、つねにバインドされています。
その他のキーバインドは、そのほとんどは、Emacs、vi(1) ユーザが予想できる
ものです。また、簡単に bindkey コマンドで表示させることもできるので、こ
こ で 、それらのバインドを並べあげる必要はないでしょう。同じく、bindkey
コマンドは、それぞれの編集コマンドを簡単な説明付きで、表示させること が
できます。
注 意: 「単語」という概念に関して、編集コマンドは、シェルと同じ概念を持
たないことに注意してください。エディタは、シェル変数 wordchars の中には
な い非英数文字 (英文字、数字のどちらでもない文字) によって単語の区切り
を決めます。一方、シェルは、ホワイトスペース (空白、タブ、改行) と、 字
句構造の項で列挙する特殊な意味を持つ文字のいくつかを識別します。
補完と一覧 (+)
シ ェルは、一意に決まる短縮形を与えられると、しばしば単語の補完を行うこ
とができます。単語の一部 (たとえば ‘ls /usr/lost’) をタイプして、タブキ
ーを押すと、編集コマンド complete-word が実行します。シェルは、ファイル
名 ‘/usr/lost’ を補完して ‘/usr/lost+found/’ にします。このとき、入力バ
ッ フ ァ の中で、不完全な単語を完全な単語で置き換えます。 (注意: 末端の
‘/’ について: 補完では、ディレクトリ名を補完すると最後に ‘/’ を付け加え
ま す。そして、ディレクトリ名以外の単語を補完すると、末尾に空白文字を付
け加えます。こうすることで、タイプ入力が速くなり、また、補完が成功し た
ことが一目で分かります。シェル変数 addsuffix のセットをはずせば、これら
を付け加えなくすることもできます。) 合致するものが見当たらない場合 ( お
そ らく ‘/usr/lost+found’ が存在しない場合でしょう)、端末のベルが鳴りま
す。単語がすでに補完されている場合 (システムに ‘/usr/lost’ が存在する場
合 か、あるいは、ユーザがはるか先まで考えて、すべてを入力してしまってい
た場合でしょう)、‘/’ または空白文字が末尾にまだなければ、付け加えられま
す。
補 完は、行の一番最後でなくても、途中どこででも機能します。そして、テキ
ストの補完によって、その分、行の残りは右方向へ押されます。単語の中間 で
補 完された場合、しばしばカーソルの右側に文字が残り、それを消すはめにな
ることもあります。
コマンドと変数は、ほとんど同じ方法で補完できます。たとえ ば 、‘em[tab]’
と タ イ プした時、使用しているシステムで ‘em’ から始まるコマンドが唯一
emacs だけならば、 ‘em’ は ‘emacs’ と補完されます。補完は、path 中の デ
ィ レクトリにあるコマンドか、フルパスが与えられれば、そこにあるコマンド
を見つけ出すことができます。 ‘echo $ar[tab]’ とタイプした時、他に ‘ar’
から始まる変数がなければ、 ‘$ar’ は ‘$argv’ と補完されます。
シ ェルは、入力バッファを解析して、補完したい単語を、ファイル名としてか
、コマンドとしてか、変数としてか、どのように補完すべきかを決めます。 バ
ッファの中の最初の単語と、‘;’, ‘|’, ‘|&’, ‘&&’, ‘||’ のすぐ次にくる単語
は、コマンドとみなします。 ‘$’ で始まる単語は、変数とみなします。その他
の ものは、ファイル名とみなします。空の行は、ファイル名として ‘補完され
て’ います。
いつでも、‘^D’ とタイプすることで、編集コマンド delete-char-or-list-or-
eof を実行させて、補完可能な単語の候補を並べ挙げることができます。シェ
ルは、組み込みコマンド ls-F (q.v.) を使って、補完可能な候補を並べ挙げま
す 。そして、プロンプトと未完成のコマンドラインを再表示します。次に例を
示します。
> ls /usr/l[^D]
lbin/ lib/ local/ lost+found/
> ls /usr/l
シェル変数 autolist をセットしていれば、シェルは、補完に失敗したとき は
いつでも残りの選択肢を表示します。
> set autolist
> nm /usr/lib/libt[tab]
libtermcap.a@ libtermlib.a@
> nm /usr/lib/libterm
シ ェル変数 autolist を ‘ambiguous (あいまいな)’ にセットした場合は、補
完に失敗して補完される単語へ新しい文字をそれ以上追加できなくなったと き
に限り、選択肢を表示します。
補完するファイル名には、変数、自分もしくは他人のホームディレクトリ (‘~’
で短縮したもの。ファイル名置換の項を参照)、ディレクトリスタックエントリ
(‘=’ で短縮したもの。ディレクトリスタック置換の項を参照) を含めることが
できます。たとえば、次のようになります。
> ls ~k[^D]
kahn kas kellogg
> ls ~ke[tab]
> ls ~kellogg/
あるいは、
> set local = /usr/local
> ls $lo[tab]
> ls $local/[^D]
bin/ etc/ lib/ man/ src/
> ls $local/
変数については、編集コマンド expand-variables を指定して使っても展開 で
きることに注意してください。
コ マンド delete-char-or-list-or-eof は、行の最後でのみリストを表示しま
す。行の中間の場合、カーソル位置の文字を消去します。空行の場合、ログ ア
ウ ト し ま す 。ただし、ignoreeof がセットされていれば、何もしません。
‘M-^D’ は、編集コマンド list-choices にバインドされていますが、これは行
中 の ど こ でも、補完の候補のリストを表示します。 list-choices (または
、delete-char-or-list-or-eof のところで列挙するコマンドで、消去するコマ
ン ド、しないコマンド、リスト表示するコマンド、ログアウトするコマンドの
どれでも) は、そうしたい場合、組み込みコマンド bindkey で ‘^D’ にバイン
ドすることもできます。
編 集コマンド complete-word-fwd と complete-word-back (デフォルトでは、
どのキーにも割り付けられていません) を使うことで、補完候補のリストを 上
または下に順に巡り、リスト上の現在の単語を、次の単語または 1 つ前の単語
に置き換えることができます。
シェル変数 fignore に、補完の際に無視するファイルのサフィックスのリスト
をセットできます。次の例を考えてみます。
> ls
Makefile condiments.h~ main.o side.c
README main.c meal side.o
condiments.h main.c~
> set fignore = (.o \~)
> emacs ma[^D]
main.c main.c~ main.o
> emacs ma[tab]
> emacs main.c
‘main.c~’ と ‘main.o’ は、fignore にサフィックスが登録されているために
、補完では無視されます (しかしリスト上には表示されます)。ファイル名置換
の項で解説しているように、home に拡張されないようにするために、‘~’ の前
に ‘\’ が必要なことに注意してください。補完の候補が1 つしかない場合は、
fignore の設定は無視されます。
シ ェ ル変数 complete が ‘enhance(拡張)’ にセットされていた場合、補完は
1) 大文字小文字の区別を無視し、 2) ピリオド、ハイフン、アン ダ ス コ ア
(‘.’, ‘-’, ‘_’)を、単語を分ける記号であるとみなし、ハイフンとアンダスコ
アは同等なものとみなします。次のようなファイルがある場合、
comp.lang.c comp.lang.perl comp.std.c++
comp.lang.c++ comp.std.c
‘mail -f c.l.c[tab]’ とタイプすれば、‘mail -f comp.lang.c’ のように補完
さ れ、^D の場合には、‘comp.lang.c’ と ‘comp.lang.c++’ がリストとして表
示されます。 ‘mail -f c..c++[^D]’ とタイプした場合 は 、‘comp.lang.c++’
と ‘comp.std.c++’ が表示されます。次のファイルがあるディレクトリで、‘rm
a--file[^D]’ とタイプした場合、
A_silly_file a-hyphenated-file another_silly_file
の 3 つのファイルすべてが一覧表示されます。なぜならば、大文字小文字の区
別 は無視されて、ハイフンとアンダスコアは同等と解釈されるからです。しか
しながら、ピリオドは、ハイフンやアンダスコアと同等ではありません。
補完と一覧は、他にもいくつかのシェル変数の影響を受けます。その ひ と つ
、recexact をセットすると、続けてタイプすればより長い単語に合致するよう
な場合でさえも、最短で一意に一致する単語に合致するようになります。た と
えば、
> ls
fodder foo food foonly
> set recexact
> rm fo[tab]
こ の場合はベルが鳴るだけです。なぜなら、‘fo’ は、‘fod’ または ‘foo’ に
展開できるからです。しかし、さらに ‘o’ とタイプすると、
> rm foo[tab]
> rm foo
‘food’ や ‘foonly’ も合致するにもかかわらず、補完は ‘foo’ で完了しま す
。 autoexpand を セ ットすると、補完を試みる前に、毎回、編集コマンド
expand-history を実行するようになります。 autocorrect をセットすると 、
補 完を試みる前に、毎回、その単語のスペル訂正をするようになります (スペ
ル訂正の項を参照)。 correct をセットすると、‘return (enter)’ キーを押し
たあと、自動的にコマンドを補完するようになります。 matchbeep をセットす
ると、補完に際して、状況の変化に応じて、ベルを鳴らしたり、鳴らないよ う
に できます。 nobeep をセットすると、まったくベルを鳴らさないようにでき
ます。 nostat には、ディレクトリのリストやディレクトリに合致するパタ ー
ンをセットでき、これらのディレクトリで補完機構が stat(2) を実行しないよ
うにすることができます。 listmax や listmaxrows にセットすることで、 ま
ず 問い合わせずに一覧表示する項目の数や、列の数を、それぞれ制限すること
ができます。 recognize_only_executables をセットすると、シェルがコマ ン
ド 一覧を表示する際に、実行可能ファイルだけを一覧表示するようにさせるこ
とができます。ただし、動作はきわめて遅くなります。
最後に、組み込みコマンド complete を使って、ファイル名、コマンド、変 数
以 外の単語を補完する方法をシェルに教えることができます。補完と一覧は、
グロブパターン (ファイル名置換の項を参照) 上では機能しませんが、編集 コ
マ ンド list-glob と expand-glob はグロブパターンに対し同等の機能として
実行されます。
スペル訂正 (+)
シェルは、補完したり一覧表示するのと同様に、ファイル名、コマンド、変 数
名のスペルを訂正することができることがあります。
個々の単語は、編集コマンド spell-word (普通は M-s と M-S にバインドされ
ています) でスペル訂正できます。入力バッファ全体は spell-line (普通 は
M-$ に割り付けられています) でスペル訂正できます。シェル変数 correct に
‘cmd’ を設定されておけば、コマンド名がスペル訂正されます。‘all’ を設 定
し て お けば、リターンがタイプされるたびに行全体がスペル訂正されます。
autocorrect がセットされていれば、単語に補完を試みる前にその単語をス ペ
ル訂正します。
ス ペル訂正が、ここで説明した方法のいずれかにより呼び出され、コマンド行
のどこかにスペル誤りがあると判断すると、シェルは、次のように訂正済み の
コマンド行を表示し入力を待ちます。
> set correct = cmd
> lz /usr/bin
CORRECT>ls /usr/bin (y|n|e|a)?
これに対し、‘y’ または空白文字で答えると、訂正済み行を実行し、 ‘e’ で答
えると、入力バッファに訂正前のコマンドを残し、 ‘a’ で答えると、‘^C’ が
押 された場合と同様にコマンドを中止し、それ以外の場合は、元のままの行を
変えないで実行します。
スペル訂正は、ユーザ定義の補完を識別します (組み込みコマン ド complete
を参照)。もし、補完が実行される位置で、入力された単語が補完リストの中の
単語に似ていたとき、スペル訂正は、ミススペル記録して、見つかった単語 を
訂 正候補として提案します。しかし、入力された単語がその位置で、どの補完
候補にも合致しなかった時、スペル訂正は、ミススペルを示しません。
補完と同様、スペル訂正は行のどこでも機能します。行の残りを右に押し出 し
たり、残りの余分な文字をカーソルの右に残したりします。
注 意: スペル訂正は、意図どおりに動作する保証はありません。そして、ほと
んど実験的な機能として提供されています。提案、改善する点があれば歓迎 し
ます。
編集コマンド (+)
‘bindkey’ はキーバインド一覧を表示し、 ‘bindkey -l’ は編集コマンドの一
覧と短い解説を表示します。ここでは、新しい編集コマンド、または、特に 興
味 深い編集コマンドについてのみ解説します。エディタのキーバインド割り付
けの記述については、 emacs(1) と vi(1) を参照してください。
デフォルトでそれぞれのコマンドにバインドられた文字 (あるいは複数 文 字)
は 、 括 弧 の 中 に 示しました。 ‘^character’ は制御文字を意味します。
‘M-character’はメタ文字です。メタキーがない端末の場合は、escape-charac-
ter とタイプします。大文字小文字の区別はありますが、デフォルトで英文字
に割り付けられるコマンドは、便宜上、大文字、小文字の両方にキーバイン ド
されています。
complete-word (tab)
補完と一覧の項で解説しているとおり、単語を補完します。
complete-word-back (not bound)
complete-word-fwd と同様ですが、単語リストの終わりから、上へあ
がって行きます。
complete-word-fwd (not bound)
現在の単語を、補完可能単語リスト上の始めの単語で置き換えます 。
本 コマンドを繰り返すことで、単語リスト上を下へ降りていくことが
できます。単語リストの最後までいくと、ベルが鳴り、未補完の単 語
へ戻ります。
complete-word-raw (^X-tab)
complete-word と同様ですが、ユーザ定義した補完は無視されます。
copy-prev-word (M-^_)
現 在の行で、1 つ前の単語を入力バッファへコピーします。 insert-
last-word も参照してください。
dabbrev-expand (M-/)
以前入力した単語の中で、現在の単語が先頭部分文字列であり、し か
も 最近のものを見つけて、それで展開します。必要ならば、ヒストリ
リストを一周回って元に戻って探します。 dabbrev-expand を中断 せ
ず 繰 り 返すことで、その次の単語に変わります。 history-search-
backward と同様に、同一のマッチングはスキップします。
delete-char (割り付けなし)
カーソル下の文字を削除します。 delete-char-or-list-or-eof も 参
照してください。
delete-char-or-eof (割り付けなし)
カーソル下に文字があれば delete-char を実行し、空行では end-of-
file を実行します。 delete-char-or-list-or-eof も参照してくださ
い。
delete-char-or-list (割り付けなし)
カ ー ソ ル 下に文字があれば delete-char を実行し、行の末尾では
list-choices を実行します。 delete-char-or-list-or-eof も参照し
てください。
delete-char-or-list-or-eof (^D)
カ ー ソ ル 下に文字があれば delete-char を実行し、行の末尾では
list-choices を実行し、空行では end-of-file を実行します。こ れ
らの 3 つのコマンドも参照してください。これらのコマンドは、それ
ぞれ 1 つの動作を実行するだけです。 delete-char-or-eof, delete-
char-or-list, list-or-eof は、それぞれ 3 つのうちの異なる 2 つ
を実行します。
down-history (下矢印, ^N)
up-history と同様ですが、1 つずつ下に移動し、もとの入力行で止ま
ります。
end-of-file (割り付けなし)
フ ァ イ ル の 終 端 であることをシェルに通知します。シェル変数
ignoreeof (そちらも参照) がセットされていない場合、その結果とし
て 、シェルは実行を終了します。 delete-char-or-list-or-eof も参
照してください。
expand-history (M-space)
現在の単語のヒストリ置換を展開します。ヒストリ置換を参照して く
だ さ い 。 magic-space, toggle-literal-history と、シェル変数
autoexpand も参照してください。
expand-glob (^X-*)
カーソルの左にグロブパターンを展開します。ファイル名置換を参 照
してください。
expand-line (割り付けなし)
expand-history と同様ですが、入力バッファのそれぞれの単語のヒス
トリ置換を展開します。
expand-variables (^X-$)
カーソルの左に変数を展開します。変数置換を参照してください。
history-search-backward (M-p, M-P)
ヒストリリストを後方へ向かって、入力バッファの現在の中身 (カ ー
ソ ル位置まで) で始まるコマンドを検索し、それを入力バッファへコ
ピーします。検索文字列は、‘*’, ‘?’, ‘[]’, ‘{}’ を含んだグロブパ
タ ーン (ファイル名置換を参照) であってもかまいません。 up-his-
tory と down-history は、ヒストリリストの該当する地点から始める
事ができます。 Emacs モードのみです。 history-search-forward と
i-search-back も参照してください。
history-search-forward (M-n, M-N)
history-search-backward と同様ですが、前方へ検索します。
i-search-back (割り付けなし)
後方へ、history-search-backward のように検索して、最初に合致 し
た ものを入力バッファへコピーし、カーソルをパターンの最後に位置
させます。そして、‘bck: ’プロンプトと最初に合致したものを表示し
ま す。追加の文字をタイプして、その検索を延長することができます
。 i-search-back をタイプして、同じパターンで検索を延長すること
も できます。必要があれば、ヒストリリストを一周回って元に戻って
検索を続けます。 (これを行うためには、i-search-back は、1 文 字
に バインドされていなければなりません。) あるいは、以下の特殊文
字をタイプすることもできます。
^W カーソル下の単語の残りを検索パターンに加えます。
delete (あるいは backward-delete-char にバインドされた文字)
最後にタイプされた文字の効果をとりけし、適当なら 検
索パターンから文字を削除します。
^G 前の検索が成功していたなら、検索全体を中止します。
そうでないなら、一番最後に成功した検索まで戻りま す
。
escape 検索を終え、入力バッファの現在の行をそのまま残しま
す。
この他の文字で、self-insert-command にバインドされている以外 の
も のをタイプすると、検索が終了します。入力バッファの現在の行は
そのままになり、タイプした文字は通常の入力として解釈されます 。
特 に 、 キャリッジリターンの場合は、現在の行を実行に移します。
Emacs モードのみです。 i-search-fwd と history-search-backward
も参照してください。
i-search-fwd (割り付けなし)
i-search-back と同様ですが、前方へ検索します。
insert-last-word (M-_)
1 つ前の入力行 (‘!$’) の最後の単語を入力バッファに挿入します。
copy-prev-word も参照してください。
list-choices (M-^D)
補完と一覧で解説しているように、補完の可能性を一覧表示します 。
delete-char-or-list-or-eof と list-choices-raw も参照してくださ
い。
list-choices-raw (^X-^D)
list-choices と同様ですが、ユーザ定義された補完を無視します。
list-glob (^X-g, ^X-G)
カーソルの左側のグロブパターン (ファイル名置換を参照) に合致 し
たものを (組み込みコマンド ls-F を用いて) 一覧表示します。
list-or-eof (割り付けなし)
list-choices を実行するか、または、空行の場合 end-of-file を実
行します。delete-char-or-list-or-eof も参照してください。
magic-space (割り付けなし)
まず expand-history と同様に、現在の行のヒストリ置換を展開し て
、 その後で空白を 1 つ付け加えます。 magic-space はスペースキー
にバインドするように設計されていますが、デフォルトではバイン ド
されていません。
normalize-command (^X-?)
パ スの中の現在の単語を検索します。そして、見つかった場合、実行
可能ファイルを指すフルパスで置き換えます。特殊文字はクォート さ
れ ます。エイリアスは展開されて、クォートされますが、エイリアス
中のコマンドは展開 / クォートされません。このコマンドは、たとえ
ば、‘dbx’ や ‘sh -x’ などのように、コマンドが引数を取得する場合
に役立ちます。
normalize-path (^X-n, ^X-N)
シェル変数 symlinks の設定 ‘expand’ の項で説明されているよう に
、現在の単語を展開します。
overwrite-mode (割り付けられていません)
入力モードと上書きモードの間で切り替えます。
run-fg-editor (M-^Z)
現在の入力行を保存します。そして、環境変数 EDITOR または VISUAL
のファイル名部分の最後の構成要素 (または、どちらもセットされ て
い なければ、‘ed’ か ‘vi’) と等しい名前を持ち、ストップしている
ジョブを探します。そのようなジョブが見つかれば、‘fg %job’ と タ
イ プしたのと同じように、実行再開されます。これは、エディタとシ
ェルの間を抜けて交互に切り替えるのを容易にするために使われま す
。 このコマンドを ‘^Z’ にバインドし、もっと簡単に交互の切り替え
ができるようにする人もいます。
run-help (M-h, M-H)
補完ルーチンの ‘現在のコマンド’ と同じ概念による現在のコマン ド
の ドキュメントを検索し、表示します。ページャを使う方法はありま
せん。run-help は短いヘルプファイルとのために設計されているため
です。特別なエイリアス helpcommand が定義されていた場合、コマン
ド名を唯一の引数としてその値が実行されます。ほかに、ドキュメ ン
ト のファイル名は、コマンド名.help, コマンド名.1, コマンド名.6,
コマンド名.8, コマンド名のいずれかでなければなりません。また 、
そのファイルは、環境変数 HPATH の中で、一覧にあがっているディレ
クトリのうちの 1 つに入っていなければなりません。もし、1 つ以上
のヘルプファイルがある場合は、最初の 1 つのみがプリントされます
。
self-insert-command (テキスト文字)
挿入モード (デフォルト) では、タイプした文字を、カーソル下の 文
字 の後に挿入します。上書きモードでは、タイプした文字で、カーソ
ル下の文字を置き換えます。入力モードは、通常、各行の間で維持 さ
れていますが、シェル変数 inputmode を ‘insert(挿入)’ あるいは、
‘overwrite(上書き)’ にセットしておくと、エディタを、各行の始 ま
り で、そのモードにすることができます。 overwrite-mode も参照し
てください。
sequence-lead-in (矢印接頭辞、メタ接頭辞、^X)
次に続く文字がマルチキーシーケンス (複数文字の連続) であるこ と
を 表します。マルチキーシーケンスをコマンドにバインドする場合、
実際には、次の 2 つのバインドを作ります。まず、最初 の 文 字 を
sequence-lead-in とします。そして、シーケンス全体をそのコマンド
にバインドします。 sequence-lead-in にバインドされた文字で始 ま
る すべてのシーケンスは、他のコマンドにバインドされていなければ
、実質的には undefined-key にバインドされたのと同じことになりま
す。
spell-line (M-$)
spell-word と同様に、入力バッファ中の各単語のスペル訂正を試みま
す。しかし、単語の最初の文字が、 ‘-’, ‘!’, ‘^’, ‘%’ のうちの ど
れかの場合と、単語中に ‘\’, ‘*’, ‘?’ のいずれかを含んでいる場合
は、スイッチや、置換などの問題を避けるために、これらの単語を 無
視します。スペル訂正を参照してください。
spell-word (M-s, M-S)
ス ペル訂正の項で説明されているのと同じやり方で、現在の単語のス
ペルの訂正を試みます。パス名として現れる単語の部分をそれぞれ に
チェックします。
toggle-literal-history (M-r, M-R)
入力バッファのヒストリ置換を展開したり、‘しなかったり’ します。
expand-history と、シェル変数 autoexpand も参照してください。
undefined-key (割り付けのコマンドが無いキー)
ベルを鳴らします。
up-history (上矢印, ^P)
ヒストリリストの中から 1 つ前のエントリを入力バッファにコピーし
ます。 histlit がセットされている場合、その記入された文字どおり
の形式を使います。ヒストリリストを上の方へ 1 つずつ移動を繰り返
した場合、一番上で止まります。
vi-search-back (?)
検 索文字列 (history-search-backward と同様、グロブパターンでも
構いません) の入力のために ‘?’ をプロンプト表示します。その文字
列 を検索して、同じ文字列を入力バッファへコピーします。合致する
ものが見つからなければ、ベルが鳴ります。リターンキー (enter キ
ー) を押すと、検索を終了して、入力バッファ中に最後に合致した単
語を残します。 escape キーを押すと、検索を終了して、合致した も
のを実行します。 vi モードのみです。
vi-search-fwd (/)
vi-search-back と同様ですが、前方へ検索します。
which-command (M-?)
入力バッファの最初の単語に対して、which (組み込みコマンドの解説
を参照) を実行します。
字句構造
シェルは入力された行をタブや空白で単語に分割します。特殊文字 ‘&’, ‘|’,
‘;’, ‘<’, ‘>’, ‘(’, ‘)’, 2 文字繰り返しの ‘&&’, ‘||’, ‘<<’ , ‘>>’ は、
空白で囲まれているかどうかにかかわらず、常に単語の区切りになります。
シェルの入力が端末からではないとき、文字 ‘#’ は、コメントの始まりとして
扱 われます。‘#’ とその後ろの入力行の残りはコメントと解釈され、文法解析
されずに捨てられます。
特殊文字 (空白、タブ含む) は、その文字の直前にバックスラッシュ ‘\’ を置
くことで、または、単一引用符 ‘’’、二重引用符 ‘"’、逆引用符 ‘‘’ で囲むこ
とで、特殊な意味合いを持たないようにしたり、場合によっては、他の単語 の
一 部分にすることもできます。他に引用がなされない限り、‘\’ の直後に改行
文字を置くと、改行文字は空白扱いになります。しかし、引用中では、この 文
字の並びは改行文字になります。
さ らに、ヒストリ置換を除く、すべての置換 (次項を参照) は、置換を含む文
字列 (あるいは文字列の一部) を単一引用符で囲むことで防ぐことができま す
。あるいは、重大な文字 (たとえば、変数置換ならば ‘$’ や、コマンド置換な
らば ‘‘’) を ‘\’ でクォートすることで防ぐことができます。(エイリアス 置
換も例外ではありません。一度定義された alias に対して、何らかの方法でそ
の単語のどれかの文字をクォートすることで、そのエイリアスの置換を防ぐ こ
と ができます。エイリアスをクォートする普通の方法は、そのエイリアスの前
にバックスラッシュを置くことです。) ヒストリ置換は、バックスラッシュ を
用 いることで防ぐことができますが、単一引用符では防ぐことができません。
。二重引用符、逆引用符でクォートされた文字列は、変数置換とコマンド置 換
は受けますが、その他の置換は受けません。
単 一引用符、二重引用符で囲まれたテキストは 1 つの単語 (またはその一部)
となります。それらの文字列中のメタ文字 (空白、タブを含む) は、単語を 分
割 しません。ひとつだけ特殊な場合 (次のコマンド置換を参照) として、二重
引用符で囲まれた文字列を 1 つ以上の単語に分けることができます。これは、
単 一引用符で囲まれた文字列では決してできません。逆引用符は特殊で、コマ
ンド置換 (そちらも参照) に、影響を与え、その結果が 1 つ以上の単語になる
こともあります。
複 雑な文字列をクォートする場合、特に、文字列自身にクォート文字が含まれ
ている場合は、わかりにくいかもしれません。人間が書いたものの中では、 引
用符を引用のために使う必要はないことを忘れないように! 文字列全体をクォ
ートするのではなく、もし適当ならば異なるタイプの引用符を用い、クォー ト
す る必要のある文字列の一部分のみをクォートすることの方が、簡単かもしれ
ません。
シェル変数 backslash_quote (そちらも参照) をセットすると、バックスラ ッ
シュが常に ‘\’, ‘’’, ‘"’ をクォートするようにできます。(+) これによって
、複雑な引用をする仕事が簡単になるかもしれません。しかし csh(1) のス ク
リプトでは、構文エラーの原因になります。
置換
こ こで、シェルが入力に対して行うさまざまな変換を、処理が行われる順に記
述します。同時に、処理に関わるデータ構造と、データ構造に影響を与える コ
マ ンドと変数とにも触れておきます。字句構造のところで説明する引用により
、置換を抑制できることを覚えておいてください。
ヒストリ置換
端末から入力したコマンドひとつひとつ (イベント) は、ヒストリリストに 保
存 されます。直前のコマンドは常に保存されます。さらに、保存するコマンド
数を、シェル変数 history に設定することができます。重複するイベントを保
存 するかどうか、同じイベントの連続をそのまま保存するかどうかを、シェル
変数 histdup に設定することができます。
保存されたコマンドには、1 から始まる連続した番号が振られ、タイムスタ ン
プ が打たれます。普通イベント番号を用いる必要はありませんが、シェル変数
prompt の中に ‘!’ を置くことで、現在のイベント番号をプロンプトの一部 に
することができます。
実 際のところ、シェルは、ヒストリを展開形式と文字どおり (未展開) の形式
とで保存しています。シェル変数 histlit を設定しておくと、ヒストリを表示
する / ヒストリに保存するコマンドで文字どおりの形式を用いるようになりま
す。
組み込みコマンド history により、ヒストリリストの表示、ファイルに保存、
フ ァ イルからの読み込み、クリアをいつでも行えます。シェル変数 savehist
と histfile により、ヒストリリストのログアウト時の自動保存と、ログイ ン
時の自動読み込みを設定することができます。
ヒ ストリ置換により、ヒストリリストから単語の列を入力ストリームに持ち込
みます。これにより、前のコマンドの繰り返し、前のコマンドで使った引数 の
繰 り返し、前のコマンドで間違えたスペルの修正をわずかなキー入力で、かな
り確実に容易に行うことができるようになります。
ヒストリ置換は、文字 ‘!’ で始まります。ヒストリ置換は、入力ストリームの
どこから開始してもかまいませんが、入れ子にはできません。文字 ‘!’ の前に
‘\’ を置くことで、‘!’ の特殊な意味を打ち消すことができます。文字 ‘!’ が
、空白文字、タブ文字、改行文字、‘=’、‘(’ の前にある場合は、そうした方が
便利なので、無変更のまま渡されます。入力行が ‘^’ で始まる場合にも、ヒス
ト リ置換が生じます。この省略表現については後で説明します。ヒストリ置換
を示すための文字 (‘!’ と ‘^’) は、シェル変数 histchars を設定することに
よ り変更することができます。入力行がヒストリ置換を含む場合、実行前に置
換結果が常に表示されます。
ヒストリ置換には「イベント指定」、「単語指定子 (word designator)」、 「
修飾子 (modifier)」を含めることができます。イベント指定は、どのイベント
から単語の列を取り出すかを指定します。単語指定子は、選択したイベント か
ら どの単語を選ぶかを指定します。修飾子は、選択した単語をどう操作するか
を指定します。
イベント指定には、次のものがあります。
n 番号: これはある特定のイベントを指定します。
-n オフセット: これは現在のイベントの前 n 個目のイベントを指定
します。
# 現在のイベントを指定します。これは csh(1) の中では注意して
扱わねばなりません。csh(1) では、再帰呼び出しのチェックをし
ていないからです。tcsh では、再帰呼び出しは 10 レベルまで許
されています。(+)
! 1 つ前のイベントを指定します (‘-1’ と等価)。
s 先頭の単語が s で始まるイベントのうち、最も新しいものを指定
します。
?s? 文字列 s を含むイベントのうち、最も新しいものを指定します。
直後が改行文字の場合は、2 番目の ‘?’ は省略可能です。
たとえば、次のようなヒストリリストがあるとします。
9 8:30 nroff -man wumpus.man
10 8:31 cp wumpus.man wumpus.man.old
11 8:36 vi wumpus.man
12 8:37 diff wumpus.man.old wumpus.man
コマンドが、イベント番号とタイムスタンプ付きで表示されています。現在 の
イ ベ ントは、まだ入力していませんが、イベント 13 です。 ‘!11’ と ‘!-2’
は、イベント 11 を指します。‘!!’ は、直前のイベントであるイベント 12 を
指 します。‘!!’ は、後ろに ‘:’ が付いている場合、‘!’ と省略することがで
きます (‘:’ は後で説明します)。‘!n’ は、‘n’ から始まっている、イベン ト
9 を指します。‘!?old?’ は、‘old’ を含んでいるイベント 12 を指します。単
語指示子も単語修飾子もどちらも含まない場合、ヒストリ参照はそのイベン ト
全 体 を 展開するだけです。ですから、コピーコマンドを再実行したいときは
‘!cp’ と入力しますし、‘diff’ の出力が画面上端からスクロールして消えてし
まう場合、‘!!|more’ と入力します。
必 要に応じ、中括弧で囲むことで、ヒストリ置換を前後のテキストから分離す
ることができます。たとえば、‘!vdoc’ とすると、‘vdoc’ で始まるコマンドを
探 しますが、この例で見つからないにしても、‘!{v}doc’ では、あいまいさも
なく ‘vi wumpus.mandoc’ に展開されます。中括弧の中でも、ヒストリ置換 は
入れ子になりません。
(+) csh(1) では、たとえば ‘!3d’ は、イベント 3 の後ろに英文字 ‘d’ を付
加して展開しますが、tcsh では、これを ‘3d’ で始まるイベントのうち最新の
も のに展開します。つまり、完全な数値引数だけをイベント番号と見なします
。これにより、数字から始まるイベントを呼び出すことが可能 と な り ま す
。‘!3d’ を csh(1) のように展開させるには、‘!\3d’ と指定してください。
イ ベントから単語を選択する場合、‘:’ と選択する単語を表す指示子を使い、
イベント指定を行うことができます。入力行の単語には、0 から始まる番号 が
振 られています。最初の単語 (普通、コマンドです) は 0 で、 2 番目の単語
(第 1 引数) は 1 といった具合です。基本的な単語指示子は次のようになりま
す。
0 最初の単語 (コマンド)
n n 番目の引数
^ 最初の引数、‘1’ と等価
$ 最後の引数
% ?s? 検索で一致した単語
x-y ある範囲の単語
-y ‘0-y’ と等価
* ‘^-$’ と等価。但し、イベントが 1 単語しか含まない場合は何も
返さない。
x* ‘x-$’ と等価
x- ‘x*’ と等価。但し、最後の単語 (‘$’) は除く。
選択した単語は、空白文字 1 つで区切られてコマンド行に挿入されます。たと
えば、‘diff !!:1.old !!:1’ と打ち込むことで、先の例の ‘diff’ コマンドを
入力することもできます (‘:1’ で、直前のイベントから最初の引数を選択して
い ます)。また、‘diff !-2:2 !-2:1’ と打ち込むことで ‘cp’ コマンドの引数
を選択し、入れ換えることができます。 ‘diff’ コマンドの引数の順番を気 に
し な け れ ば 、‘diff !-2:1-2’ と打ち込んでも構いませんし、単に ‘diff
!-2:*’ でも構いません。 ‘cp’ コマンドは、現在のイベントを指す ‘#’ を 使
い 、 ‘cp wumpus.man !#:1.old’ と書くことができます。‘!n:- hurkle.man’
は、 ‘nroff’ コマンドから最初の 2 単 語 を 再 利 用 し 、 ‘nroff -man
hurkle.man’ とすることになります。
文 字 ‘:’ は単語指定からイベント指定を分離しますが、引数選択子が ‘^’,
‘$’, ‘*’, ‘%’, ‘-’ で始まるとき、この文字 ‘:’ は省略可能です。たとえ ば
、 先ほどの ‘diff’ コマンドは ‘diff !!^.old !!^’ もしくは ‘diff !!$.old
!!$’ でも構わなかったのです。しかし、‘!!’ が ‘!’ に省略可能である 場 合
、‘-’ で始まる引数選択子はイベント指定として解釈されます。
ヒ ストリ参照に、イベント指定のない単語指示子があっても構いません。その
場合、直前のコマンドを参照します。 ‘diff’ の例を続けるな ら 、 単 純 に
‘diff !^.old !^’ と入力することができます。もしくは、逆順の引数を得るだ
けならば、単に ‘diff !*’ でいいです。
ヒストリ参照の中の単語は編集可能です。つまり、単語の後ろに 1 つまたは複
数の修飾子 (修飾子それぞれは ‘:’ で始まります) を付けることで「修飾」可
能です。
h 先頭のもの 1 つを残し、パス名の構成要素の後ろの部分を削除し
ます。
t 末尾のもの 1 つを残し、パス名の構成要素の先頭の部分を削除し
ます。
r ファイル名拡張子 ‘.xxx’ を削除し、名前の基本部分だけを残 し
ます。
e 拡張子だけを残し、他をすべて削除します。
u 最初の英小文字を大文字に変換します。
l 最初の英大文字を小文字に変換します。
s/l/r/ l を r で置換します。 l は r と同様に、単なる文字列です。名
付け親である ed(1) コマンドのような正規表現ではありません。
‘/’ の代わりに任意の文字を区切り文字として使うことができま
す。 ‘\’ を使い、l や r の中で区切り文字をクォートするこ と
が で きます。 r 中の文字 ‘&’ は、l で置き換えられます。‘\’
で ‘&’ もクォートできます。l が空 (‘‘’’) の場合、以前の置換
の l 、または以前のイベント指定 ‘?s?’ の s を使用します。最
後の区切り文字の直後が改行文字の場合、その区切り文字を省 略
できます。
& 以前の置換を繰り返します。
g 後ろの修飾子を単語それぞれに適用します。
a (+) 後ろの修飾子を、ある単語だけにできるだけ多くの回数、適用し
ます。 ‘a’ と ‘g’ をいっしょに用いて、修飾子をグローバル に
適用することができます。現在の実装では、修飾子 ‘a’ と修飾子
‘s’ を同時に使用すると、無限ループに陥る可能性があります 。
た とえば、‘:as/f/ff/’ は決して終わりません。この動作は今後
変更されるかもしれません。
p 新しいコマンド行を表示しますが、実行はしません。
q 置換された単語をクォートし、それ以上の置換が起きないよう に
します。
x q と同じです。ただし、単語を空白 / タブ / 改行文字のところ
で分割します。
修飾子は最初に見つかった修飾可能な単語だけに適用されます (‘g’ を使用 し
ない限り)。修飾可能な単語がない場合はエラーになります。
た とえば、先の例の ‘diff’ コマンドは、‘diff wumpus.man.old !#^:r’ とも
書くことができます。これは、‘r’ を用いて、同じ行 (‘!#^’) の最初の引数か
ら ‘.old’ を削除しています。‘echo hello out there’ と言っておいてから
、‘echo !*:u’ を使い ‘hello’ を大文字にできます。 ‘echo !*:au’ を使い大
声 で 言 うようにできます。‘echo !*:agu’ を使い絶叫させることもできます
。‘mail -s "I forgot my password" rot’ の後で ‘!:s/rot/root’ を続けるこ
とで、‘root’ のスペル間違いを直すことができます (スペル間違いの訂正につ
いては、スペル訂正の項に別のやり方があります)。
置換には特別な省略記法があります。‘^’ が入力行の先頭にある場合、 ‘!:s^’
と等価です。よって、先の例でスペルを訂正するには、 ^rot^root と言うこと
もできたわけです。これは明示的に ‘!’ で始まらないヒストリ置換としては唯
一のものです。
(+) csh では、ヒストリ展開または変数展開に適用される修飾子は 1 つだけで
す。tcsh では、1 つ以上の修飾子が使用される可能性があります。たとえば、
次のような場合を考えます。
% mv wumpus.man /usr/man/man1/wumpus.1
% man !$:t:r
man wumpus
csh では、この結果は ‘wumpus.1:r’ となります。コロンが後ろに続く置換は
、中括弧を用いてコロンと区切る必要があります。
> mv a.out /usr/games/wumpus
> setenv PATH !$:h:$PATH
Bad ! modifier: $.
> setenv PATH !{-2$:h}:$PATH
setenv PATH /usr/games:/bin:/usr/bin:.
最初の試みは csh では成功しますが、tcsh では失敗します。 こ の 理 由 は
、tcsh は 2 番目のコロンの後ろに、‘$’ ではなく修飾子があると思っている
からです。
最後に、ヒストリはここで説明してきた置換だけでなく、エディタでも利用 す
る こ と が で き ます。編集コマンド up-history, down-history, history-
search-backward, history-search-forward, i-search-back, i-search-fwd,
vi-search-back, vi-search-fwd, copy-prev-word, insert-last-word はヒス
トリリスト中のイベントを検索し、入力バッファにイベントをコピーします 。
編 集コマンド toggle-literal-history は、入力バッファでヒストリ行を展開
するか文字どおりに扱うかを切り替えます。 expand-history, expand-line は
そ れぞれ、現在の単語、または、入力バッファ全体でヒストリ置換を展開しま
す。
エイリアス置換
シェルは、エイリアスのリストを保持しています。このリス ト は 、 alias,
unalias コマンドを使って設定、削除、表示することができます。コマンド行
を解釈し単純コマンド (コマンドを参照) に分割したあと、複数のコマンド を
左 から右へ、それぞれの最初の単語がエイリアスを持っているかをチェックし
ます。エイリアスを持っている場合、最初の単語をエイリアスで置き換えま す
。 置き換えたエイリアスがヒストリ参照を含む場合、元のコマンドを直前の入
力行とみなして、ヒストリ置換 (そちらも参照) が適用されます。エイリア ス
がヒストリ置換を含まない場合、引数リストは変更されずそのままです。
そのため、たとえば ‘ls’ のエイリアスが ‘ls -l’ だった場合、コマンド ‘ls
/usr’ は ‘ls -l /usr’ になります。ここで、引数リストは影響を受けませ ん
。‘lookup’ の エイリアスが ‘grep !^ /etc/passwd’ だとすると、コマンド
‘lookup bill’ は ‘grep bill /etc/passwd’ になります。エイリアスを使い、
パ ーザのメタ記法を利用できます。たとえば、‘alias print ’pr \!* | lpr’’
は、引数をラインプリンタに pr(1) する ‘‘コマンド’’(‘print’) を定義し ま
す。
コ マンドの最初の単語がエイリアスを持たなくなるまで、エイリアス置換は繰
り返されます。(先の例のように) エイリアス置換が最初の単語を変更しない場
合 、そのエイリアスに印を付けてループが生じないようにします。それ以外の
ループは検出され、エラー扱いになります。
シェルが参照するエイリアスがいくつかあります。特殊エイリアスを参照し て
ください。
変数置換
シェルは変数のリストを管理しており、それらは 0 個またはそれ以上の個数の
単語のリストを値として持ちます。シェル変数の値は、コマンド set, unset
に より表示、変更することができます。システムは、自分自身の ‘‘環境’’ 変
数のリストを保持しています。環境変数 は コ マ ン ド printenv, setenv,
unsetenv により表示、変更することができます。
(+) ‘set -r’ (参照) により変数を読み出し専用にすることができます。読み
出し専用変数は、変更や unset ができません。これを試みるとエラーになりま
す 。一度読み出し専用にした変数は、書き込み可能に戻すことはできません。
ですから、‘set -r’ は注意して使用する必要があります。環境変数は読み出し
専用にすることはできません。
シ ェルが設定、参照する変数がいくつかあります。たとえば、変数 argv は、
シェルの引数リストの複製で、この変数の値である単語は特別な方法で参照 さ
れ ます。シェルが参照する変数の中には、トグルスイッチがあります。シェル
は、これらの変数が何の値を持っているかではなく、値が設定されているか ど
うかにだけ影響を受けます。たとえば、変数 verbose は、コマンド入力をエコ
ーするかどうかを制御するトグルスイッチです。コマンド行オプション -v が
こ の変数に値を設定します。シェルが参照する変数すべてのリストは、特別な
シェル変数にあります。
変数を数値として扱う操作もあります。コマンド ‘@’ により、数値計算を実行
し 、結果を変数に代入することが可能となります。しかしながら、変数の値は
常に (0 個以上の) 文字列として表現されています。数値として扱うために 、
空文字列は 0 と見なされます。複数の単語からなる値の、2 番目以後の単語は
無視されます。
入力行のエイリアス処理を終え、字句解析を終えた後で、そして、各コマン ド
を 実 行 する前に、‘$’ 文字をキーとして変数置換が行われます。この展開は
‘$’ の前に ‘\’ を置くことで抑止できます。ただし、‘"’ の中は別で、ここで
は 常に変数置換が行われます。また、‘’’ の中も別で、ここでは決して変数置
換が行われません。‘‘’ でクォートした文字列は後で解釈されますから、 ( 後
の コマンド置換を参照) そこでの ‘$’ 置換は後になるまで行われません。‘$’
の後ろが空白、タブ、改行文字の場合は、‘$’ 置換は発生しません。
入出力リダイレクトは、変数展開の前に識別され、別々に変数展開されます 。
そ れ以外では、コマンド名と引数リスト全体が一緒に展開されます。ですから
、 (この時点での) 最初の単語 (コマンド) から 2 つ以上の単語が生成される
可 能性があります。展開後の複数の単語のうち最初のものがコマンド名となり
、残りの単語は引数になります。
‘"’ で囲まれているか、修飾子 ‘:q’ が指定されている場合を除き、最終的 に
は 、 変 数置換の結果に対し、コマンド置換とファイル名置換が適用されます
。‘"’ で囲まれている場合、値が複数の単語で構成される変数は、 1 つの単語
(の一部) に展開されます。この単語には、その変数の値である単語が空白で区
切られたものを含みます。置換の際に修飾子 ‘:q’ が適用される場合、変数 は
複 数の単語に展開されます。それぞれの単語は空白で区切られ、以後、コマン
ド置換とファイル名置換が適用されないようにクォートされます。
シェルへの入力に変数の値を持ち込むための方法として、以下の構文があり ま
す。特に注がない限り、設定されていない値の参照はエラーになります。
$name
${name} 変数 name の値である単語に置換します。この単語は、それぞれが空
白で区切られたものです。中括弧は name とそれ以後の文字列とを 分
離し、以後の文字列も含めて 1 つの変数名として解釈されないように
します。シェル変数の名前は上限が 20 文字であり、先頭は英文字 で
、2 文字目以後は英文字か数字で構成されます。アンダスコアは英文
字と見なします。name がシェル変数ではないが、環境に設定されてい
る場合、環境の値を返します (ただし、修飾子 ‘:’ と次で示す他の形
式は利用可能です)。
$name[selector]
${name[selector]}
name の値のうち選択した単語のみで置換します。selector は ‘$’ 置
換 が適用され、1 つの数値または ‘-’ で区切った 2 つの数値で構成
することができます。変数の値の先頭の単語は 1 番目として数えます
。範囲の最初の値を省略した場合、デフォルトの値 1 になります。範
囲の最後の数値を省略した場合、デフォルトの値 ‘$#name になります
。 selector ‘*’ はすべての単語を選択します。2 番目の引数が省略
されるか、あるいは範囲に収まっている場合、範囲が空になっても エ
ラーになりません。
$0 コマンド入力を読み込んでいるファイル名で置換します。ファイル名
が不明の場合エラーになります。
$number
${number}
‘$argv[number]’ と等価です。
$* ‘$argv’ と等価です。これは ‘$argv[*]’ と等価です。
ヒストリ置換のところで説明した ‘:’ 修飾子 (‘:p’ を除く) が、上記の置 換
に対して適用できます。2 つ以上の修飾子も適用できます。 (+) ヒストリ置換
(そちらも参照) と同様に、変数置換とリテラルのコロンとを分離するために、
中括弧が必要なことがあります。修飾子は中括弧の中に置かねばなりません。
以下の置換は ‘:’ 修飾子で修飾することはできません。
$?name
${?name}
name が設定されているときは、文字列 ‘1’ で置き換えられます。設
定されていないときは、文字列 ‘0’ で置き換えられます。
$?0 現在の入力ファイル名がわかっているときは、‘1’ で置き換えられ ま
す 。わかっていないときは、‘0’ で置き換えられます。対話型のシェ
ルでは、常に ‘0’ です。
$#name
${#name}
name 中の単語の数で置き換えられます。
$# ‘$#argv’ と等価です。(+)
$%name
${%name}
name の文字数で置き換えられます。(+)
$%number
${%number}
$argv[number] の文字数で置き換えられます。(+)
$? ‘$status’ と等価です。(+)
$$ (親) シェルの (10 進数の) プロセス番号で置き換えられます。
$! 本シェルが開始したバックグラウンドプロセスのうち最新の も の の
(10 進数の) プロセス番号で置き換えられます。(+)
$_ 最後に実行したコマンドのコマンド行で置き換えます。(+)
$< 標準入力から読み込んだ 1 行を、一切解釈をせずにこの変数と置き換
えます。シェルスクリプト中で、キーボードから読み込む際に用い ま
す 。(+) csh は、‘$<:q’ と等価であるかのように、$< をクォートし
ますが、 tcsh はそうしません。それだけでなく、tcsh がユーザの入
力 行を待つとき、ユーザは割り込みを入力して、置換されるべき行が
入る列を中断することができます。しかし csh ではそうすることがで
きません。
編 集コマンド expand-variables は、通常は ‘^X-$’ にバインドされています
が、これを使って、個々の変数を対話的に展開することができます。
コマンド置換、ファイル名置換、ディレクトリスタック置換
組み込みコマンドの引数に対し、残りの置換が選択的に適用されます。選択 的
と は、行の中で評価されなかった部分は、これらの展開の対象にならないとい
う意味です。シェルの内部コマンドでないコマンドに対しては、コマンド名 は
引 数リストとは別個に置換されます。この置換は最後の方、入出力リダイレク
トを実行したあと、メインシェルの子供の中で生じます。
コマンド置換
‘‘’ で囲まれたコマンドは、コマンド置換を示します。囲まれたコマンドの 出
力 を、空白、タブ、改行文字のところで別々の単語に分割します。この出力に
変数置換、コマンド置換を実行し、元の文字列があった場所に置きます。
ニ重引用符 (‘"’) の内側のコマンド置換は、空白、タブを保存します。改行文
字 だけは新しく単語分けを行います。ただし、どのような場合でも最後の改行
文字だけは新しい単語になりません。ですから、1 行まるまる出力するよう な
コ マンドでも、コマンド置換を用いると単語の一部だけを生成することができ
ます。
ファイル名置換
単語が ‘*’, ‘?’, ‘[’, ‘{’ のいずれかの文字を含む場合、または先頭が ‘~’
で 始まる場合、その単語はファイル名置換 (あるいはグロブ (globbing) と呼
ばれます) の候補になります。このような単語をパターン (グロブパタ ー ン)
と 見なし、そのパターンにマッチするファイル名のリストをアルファベット順
で整列したもので置き換えます。
ファイル名マッチの際に、ファイル名の先頭、または ‘/’ の直後の文 字 ‘.’
は、‘/’ と同様に、明示的にマッチさせなければなりません。文字 ‘*’ は、空
文字列を含むどのような文字列にもマッチします。文字 ‘?’ は、どのような 1
文字にもマッチします。列 ‘[...]’ は、括弧の中で指定した文字のいずれかに
マッチします。‘[...]’ 内では、文字の対を ‘-’ でつなぐことで、(文字順 序
で) その 2 文字の範囲にある文字のいずれかにマッチします。
(+) グロブパターンの中には反転を指定できるものがあります。列 ‘[^...]’
は、括弧内の文字 / 範囲で指定していない文字ちょうど 1 つにマッチしま す
。
‘^’ により、グロブパターン全体を反転させることもできます。
> echo *
bang crash crunch ouch
> echo ^cr*
bang ouch
‘?’, ‘*’, ‘[]’ のいずれも使わないグロブパターンや、 ‘{}’, ‘~’ (あとで説
明します) を使うグロブパターンは、反転しても正しい結果を得られません。
メタ記法 ‘a{b,c,d}e’ は、‘abe ace ade’ の省略記法です。左から右への出現
順 序 は 保 存 さ れ ま す 。‘/usr/source/s1/{oldls,ls}.c’ は 、
‘/usr/source/s1/oldls.c /usr/source/s1/ls.c’ に展開します。マッチングの
結 果 は 下 位 の レ ベ ル で 個 別に整列され、出現順序は保存されます。
‘../{memo,*box}’ は、‘../memo ../box ../mbox’ などに展開されるでしょ う
( ここで、‘memo’ が ‘*box’ のマッチング結果とともに整列されていないこと
に注意してください)。この指定が展開された結果ファイルが存在しなくてもエ
ラ ーになりませんが、展開結果を渡した先のコマンドでエラーになる可能性は
あります。この指定は入れ子にすることができます。特殊な場合として、単 語
‘{’, ‘}’, ‘{}’ は変更されずにそのまま渡されます。
ファイル名先頭の文字 ‘~’ は、ホームディレクトリを指します。単独で用いら
れた場合、つまり ‘~’ だけの場合、シェル変数 home の値に反映されているよ
う に、呼び出したユーザのホームディレクトリに展開されます。‘~’ の直後に
英文字、数字、または文字 ‘-’ で構成される名前が続く場合、シェルはその名
前 を持つユーザを検索し、そのユーザのホームディレクトリに展開します。で
すから、‘~ken’ はたと え ば ‘/usr/ken’ に 展 開 さ れ ま す 。 ま た
、‘~ken/chmach’ は、たとえば ‘/usr/ken/chmach’ に展開されます。文字 ‘~’
の後ろに英文字でもなく ‘/’ でもない文字が続いた場合、もしくは、文字 ‘~’
が 単語の先頭以外に現れた場合、変更されずにそのまま渡されます。ですから
、 ‘setenv MANPATH /usr/man:/usr/local/man:~/lib/man’ のようなコマン ド
では、期待通りのホームディレクトリ置換が起こりません。
‘*’, ‘?’, ‘[’, ‘~’ のどれかを含むグロブパターン (‘^’ は付いていてもいな
くとも同じ) は、マッチするファイルがひとつもないとエラーになります。 し
か し、グロブパターンのリストのうちのひとつでもマッチすれば (他のものは
マッチするものがなくても) エラーになりません (したがって、たとえば ‘rm
*.a *.c *.o’ は、カレントディレクトリに ‘.a’, ‘.c’, ‘.o’ で終わるファイ
ルがひとつもないときに限ってエラーになります)。また、シェル変 数 nono-
match が設定されている場合、どれにもマッチしないパターン (あるいはパタ
ーンの列) はエラーにならずに無変換のまま残されます。
ファイル名置換を止めるために、シェル変数 noglob を設定することができ ま
す。編集コマンド expand-glob は、通常は ‘^X-*’ に結合されていますが、こ
れを使い、個々のファイル名置換の展開を対話的に行うことができます。
ディレクトリスタック置換 (+)
ディレクトリスタックはディレクトリの列であり、0 から番号付けられ、組 み
込 みコマンド pushd, popd, dirs (そちらも参照) が使用します。 dirs コマ
ンドを使用すると、ディレクトリスタックをいつでも表示でき、ファイルに 書
き 込むことができ、ファイルから読み込むことができ、そしてクリアすること
ができます。シェル変数 savedirs, dirsfile に値を設定することで、ログ ア
ウ ト時のディレクトリスタックの書き込みと、ログイン時の読み込みを自動的
に行うことができます。シェル変数 dirstack を使い、ディレクトリスタッ ク
の 中を調べることができ、ディレクトリスタックに任意のディレクトリを設定
することができます。
文字 ‘=’ の後ろに 1 桁以上の数字が続くと、それはディレクトリスタック 中
の エントリに展開されます。特殊な場合として、 ‘=-’ はスタックの最新のデ
ィレクトリに展開します。たとえば、次のようにです。
> dirs -v
0 /usr/bin
1 /usr/spool/uucp
2 /usr/accts/sys
> echo =1
/usr/spool/uucp
echo =0/calendar
/usr/bin/calendar
> echo =-
/usr/accts/sys
シェル変数 noglob, nonomatch と編集コマンド expand-glob はファイル名 置
換と同様にディレクトリスタックにも適用されます。
その他の置換 (+)
フ ァイル名を含む変換が他にいくつかあります。厳密には先に説明したものと
関係があるわけではありませんが、完全を期するためにここで説明しておき ま
す。変数 symlinks (そちらも参照) が ‘expand’ に設定されている場合、どの
ようなファイル名もフルパスに展開される可能性があります。クォートする こ
と でこの展開を止めることができ、編集コマンド normalize-path を使用する
と要求に応じて展開を止めることができます。また、編集コマンド normalize-
command は、PATH にあるコマンドを、要求に応じてフルパスに展開します。最
後に、cd と pushd は ‘-’ を以前の作業ディレクトリ (シェル変数 owd と 等
価) と解釈します。これは置換でもなんでもなく、このコマンドだけで認識さ
れる省略記法です。それでも、この表記もクォートすることでこの解釈を止 め
ることができます。
コマンド
次の 3 つのセクションでは、シェルがどのようにコマンドを実行し、それらの
入出力をどのように扱うかを説明します。
単純コマンド、パイプライン、コマンド列
単純コマンドは、単語の列であり、その最初の単語が実行されるコマンドで す
。 ‘|’ 文字によって区切られた一連の単純コマンドはパイプラインを形成しま
す。パイプライン内のそれぞれのコマンドの出力は次のコマンドの入力に接 続
されます。
単純コマンドとパイプラインは ‘;’ 文字を使ってコマンド列に組み入れること
ができ、並んでいる順に実行されます。コマンドとパイプラインは ‘||’ や
‘&&’ でコマンド列に組み込むこともでき、C 言語で扱われるのと同様に、最初
のコマンドが失敗した時にだけ (‘||’の場合)、あるいは成功した 時 に だ け
(‘&&’の場合)、次のコマンドが実行されます。
単 純コマンド、パイプライン、またはコマンド列は、括弧 ‘()’ を使って単純
コマンドを形成することができ、パイプラインやコマンド列の一部として使 用
できます。コマンド、パイプライン、またはコマンド列の後に ‘&’ を置いて実
行すると、そのコマンドの終了を待たずに次のコマンドを実行できます。
組み込みコマンド、非組み込みコマンドの実行
組み込みコマンドは、シェルの中で実行されます。パイプラインの構成要素 の
最 後以外が組み込みコマンドのとき、パイプラインは、サブシェル内で実行さ
れます。
括弧で括られたコマンドは、常にサブシェル内で実行されます。
(cd; pwd); pwd
これは、現在のディレクトリを移動することなくくホームディレクトリを表 示
(その後に現在のディレクトリを表示) し、その一方、
cd; pwd
こ の場合はホームディレクトリに移動します。括弧で括られたコマンドは、た
いてい cd が現在のシェルに影響するのを防ぐために使用します。
実行するコマンドが組み込みコマンドでないことが判明すると、シェルはそ の
コマンドを execve(2) を通じて実行しようとします。環境変数 path 内の各語
は、シェルがコマンドを検索するディレクトリを指定します。 -c, -t オプ シ
ョ ンのいずれも指定されていない場合、これらのディレクトリ内の名前を内部
テーブルでハッシュし、そのコマンドが存在する可能性のあるディレクトリ だ
けで execve(2) の実行を試みます。このことは、検索パス内のディレクトリの
数が多い場合に、コマンドの位置確定を大いに高速化します。 こ の 機 構 が
(unhash によって) オフにされ、シェルに -c または -t のオプションが与え
られるか、それぞれの path のディレクトリ構成要素のいずれかが ‘/’ で始ま
っ ていない場合、シェルは現在の作業ディレクトリと与えられたコマンド名を
結合して実行するファイルのパス名を形成します。
ファイルに実行許可であってシステムが実行可能ではない場合、 (例 : 実行可
能バイナリ、インタプリンタを指定したスクリプトではないとき)、それをシェ
ルコマンドを含むファイルであるとみなし、新しいシェルを起動してそのフ ァ
イ ルを読み込みます。シェルの特殊なエイリアスで、シェル自体ではなくイン
タプリタを指定するように設定することもできます。
慣習的な‘#!’ スクリプトインタプリタを理解しないシステム上では、シェ ル
は そ れをエミュレートするようにコンパイルされます ; シェル変数 version
を参照してください。その場合、シェルがファイルの最初の行をチェックし 、
それが ‘#!interpreter arg ...’ の形式であるかどうかを確認します。この形
式であれば、シェルは与えられた引数とともにインタプリタを起動して、そ の
ファイルを標準入力に供給します。
入出力
コ マンドの標準入力と標準出力は以下の文法に従ってリダイレクトすることが
できます:
< name ファイル name (変数、コマンド、ファイル名展開を受けます) をオー
プンし、コマンドの標準入力とします。
<< word word と 同 一の行が出現するまで、シェルの入力を読み込みます。
word は変数、ファイル名、コマンド置換を受けません。シェル入力の
行 は 読 み 込 まれるとすぐ、置換を行う前に word と比較されます
。word に ‘\’, ‘"’, ‘’’, ‘‘’ のクォートが出現しなければ、行の中
で コマンド置換が実行されます。この置換を抑制するために、‘\’ に
よって ‘$’, ‘\’, ‘‘’ をクォートすることができます。コマンド置換
に おいて、すべての空白、タブ、改行は保存されますが、最後の改行
は削除されます。読み込んだ行はすべてテンポラリファイルに保存 さ
れ、コマンドの標準入力として用いられます。
> name
>! name
>& name
>&! name
フ ァイル name を標準出力として用います。ファイルが存在しなけれ
ば作成されます。すでにファイルが存在すればその内容は切り捨て ら
れ、以前の内容は失われます。
シェル変数 noclobber がセットされている場合、ファイルが存在しな
いか文字型特殊ファイル (端末や ‘/dev/null’ のような) でなければ
エ ラーになります。これは、すでに存在するファイルを間違えて削除
してしまうことを防止します。‘!’ を用いた形式を使うと、この検 査
を抑制することができます。
‘&’ を用いた形式では、標準出力とともに診断メッセージ出力もファ
イルへリダイレクトされます。 name は、‘<’ の入力ファイル名の 場
合と同様の展開を受けます。
>> name
>>& name
>>! name
>>&! name
‘>’ と同様に、ファイル name を標準出力として用います。ただし、
コマンドの出力はファイルへ追加されます。変数 noclobber がセット
さ れている場合、ファイルが存在しなければエラーとなります。 ‘!’
を用いることで、この検査を抑制することができます。
コマンドは、シェルが起動されたときの環境を引き継ぎます。ただしこの環 境
は 入出力のパラメータによって変更されますし、コマンドがパイプラインの中
にあった場合も変更されます。したがって、以前のいくつかのシェルとは異 な
り 、シェルのコマンドファイルから起動されたコマンドは、デフォルトではそ
のコマンドのテキストへアクセスできません。かわりにそれらのコマンドは 、
シ ェルのもともとの標準入力をそのまま受け継ぎます。シェルスクリプトの内
部で、コマンドにあらかじめ決まった (inline) データを渡す場合には、標 準
入 出力の形式ではなく、 ‘<<’ の機構を使うことができます。このように制限
することにより、シェルコマンドスクリプトをパイプラインの一部として用 い
る ことができます。バックグラウンドで実行されているコマンドの標準入力も
/dev/null 等にリダイレクトされることなく、シェルの標準入力をそのまま 受
け 継いでいます。もし標準入力が端末で、コマンドが端末から読み込もうとし
た場合、そのプロセスはブロックされ、シェルはユーザにそのことを通知し ま
す (ジョブの項を参照)。
診断メッセージ出力もパイプにリダイレクトすることができます。単に ‘|’ の
かわりに ‘|&’ を使います。
シェルは、標準出力のリダイレクトなしで、診断メッセージ出力をリダイレ ク
ト できなくなります。そのため、‘(コマンド > 出力ファイル) >& エラーファ
イル’ は、無難な予備手段としてされてます。出力ファイル、エラーファイ ル
のどちらかが、端末に出力を送るための ‘/dev/tty’ です。
特徴
こ こではシェルがどのようにコマンドラインを受け入れ、解釈し、実行するか
を説明しました。次は、便利な特徴について説明します。
制御フロー
このシェルには、コマンドファイル (シェルスクリプト) や (制約はあるも の
の 便利な) 端末からの入力処理の流れを制御するために使用できる多くのコマ
ンドを備えています。これらのコマンドは、入力の再読み込みや読み飛ばし を
行 うためシェルを強制的に操作します。これらの実装のために、幾つかのコマ
ンドには制限があります。
foreach、switch、while 文は、 if 文の if-then-else 形式と同様に、後で示
す ように入力行の単独の単純コマンド中に主要なキーワードが現れることを要
求します。
シェルの入力がシーク可能でない場合は、ループが読み込まれると常に入力 を
バ ッファし、この内部バッファをシークすることでループによる再読み込みを
可能にします。 (これを許可した結果、後方へ向かう goto がシーク可能で な
い入力についても成功することになります。)
式
組み込みコマンドの if, while, exit は共通した文法を持った式を使います。
式には、次の 3 つのセクションの中で説明される任意の演算子を含めることが
できます。 @ 組み込みコマンド (そちらも参照) 自体は、文法を区切るので注
意してください。
論理演算子, 算術演算子, 比較演算子
これらの演算子は C の演算子と同じ優先順位となっています。演算子には、次
のものがあります。
|| && | ^ & == != =~ !~ <= >=
< > << >> + - * / % ! ~ ( )
こ こ に 挙げた演算子は右側のものほど優先順位が高くなっています。ただし
、‘==’ ‘!=’ ‘=~’ ‘!~’ の 4 つ、‘<=’ ‘>=’ ‘<’ ‘>’ の 4 つ、 ‘<<’ ‘>>’ の
2 つ、‘+’ ‘-’ の 2 つ、‘*’ ‘/’ ‘%’ の 3 つはそれぞれ同一のグループに所
属しており、同じグループに所属している演算子の優先順位は同じレベルと な
っています。演算子 ‘==’ ‘!=’ ‘=~’ ‘!~’ は引数を文字列として比較します。
他の演算子はすべて数値で比較します。演算子 ‘=~’ ‘!~’ は ‘!=’ ‘==’ と 似
て いますが、左側のオペランドにマッチするグロブパターン (ファイル名置換
を参照) を右側に置くことが異なります。必要なものに対してだけパターン マ
ッ チを行うので、シェルスクリプト中における switch 組み込みコマンドの使
用の必要を減らします。
‘0’ で始まる文字列は 8 進数とみなされます。空の文字列や引数がぬけている
ものは ‘0’ とみなされます。すべての式の結果は 10 進数で表される文字列に
なります。特に、式の構成要素が同一の単語中に複数個現れることはないと い
う ことに注意してください。例外として、パーサに文法的に特別な意味を持つ
式の構成要素 (‘&’ ‘|’ ‘<’ ‘>’ ‘(’ ‘)’) が隣りにくることは構いません。た
だし、これらは空白で区切られるべきです。
コマンド終了ステータス
式 の中でコマンドを実行することができ、式を中括弧 (‘{}’) で囲むと終了ス
テータスが返されます。中括弧は、コマンドの単語から空白で区切ることを 忘
れ ないでください。コマンドの実行が成功した場合は、真 (たとえば ‘1’) を
返します。コマンドが 0 のステータスで終了した場合、または実行に失敗した
場 合は、偽 (たとえば ‘0’) を返します。もっと詳しいステータスの情報が必
要な場合は、コマンドを式の外部で実行し、シェル変数 status を調べてく だ
さい。
ファイル問い合わせ演算子
これらの演算子のうち幾つかはファイルと関連するオブジェクトについて真/偽
の判定を行います。これらは -op file の形式です。 op は次のうちのどれ か
1 つです。
r 読み取りアクセス
w 書き込みアクセス
x 実行アクセス
X パス中にある実行可能ファイルやシェル組み込みコマンド。たとえば
‘-X ls’ と ‘-X ls-F’ は一般に真であり、 ‘-X /bin/ls’ はそうでは
ない (+)
e 存在
o 所有者
z サイズ 0
s サイズが 0 でない (+)
f 通常ファイル
d ディレクトリ
l シンボリックリンク (+) *
b ブロック型特殊ファイル (+)
c キャラクタ型特殊ファイル (+)
p 名前付きパイプ (fifo) (+) *
S ソケット型特殊ファイル (+) *
u set-user-ID ビットがセットされている (+)
g set-group-ID ビットがセットされている (+)
k スティッキービットがセットされている (+)
t file (これは数字でなければならない) は端末デバイスに対してオー
プンしているファイル記述子である (+)
R migrate されている (convex システムのみ有効) (+)
L 多重演算子の中でこの演算子の後にくる演算子は、シンボリックリ ン
ク が指されているファイルではなく、シンボリックリンクそのものに
適用される (+) *
file はコマンドと展開されたファイル名で、指定された実ユーザに対する関係
が あるかどうかテストします。 file が存在していない場合、もしくはアクセ
スできない場合、 ‘*’ で示した演算子については、指定のファイルタイプが現
在 の システムに存在していなければすべての問い合わせは偽 (たとえば ‘0’)
を返します。
s true これらの演算子は、簡潔にするために連結することができます。 ‘-xy
file’ は ‘-x file && -y file’ と等価です。(+) たとえば ‘-fx’ は通常の実
行可能ファイルに対しては真 (‘1’ を返す) ですが、ディレクトリに対して は
そうではありません。
s L は多重演算子の中で使用できます。この演算子の後にくる演算子は、シン
ボリックリンクが指されているファイルではなく、シンボリックリンクその も
の に適用されます。たとえば ‘-lLo’ は呼び出しユーザが所有しているリンク
に対しては真です。 Lr, Lw, Lx はリンクに対しては常に真で、リンクでな い
ものに対しては偽です。 L は多重演算子の中で最後の演算子になった場合、異
なった意味を持ちます。以下を参照してください。
s file に渡すべき演算子と、そうでない演算子 (たとえば X と t) を連結 す
る ことは可能ですが、実用的ではなく、しばしば間違いの元になります。特に
、ファイルでない演算子に L をつけると、妙な結果になります。
他の演算子は他の情報、つまり単なる ‘0’ や ‘1’ だけではない情報を返し ま
す 。(+) これらは前に示したのと同じ書式になります。 op は次のうちのどれ
か 1 つです。
A エポックからの秒数で表した、最後にファイルにアクセスした 時
間
A: A と同じで、タイムスタンプの書式。例: ‘Fri May 14 16:36:10
1993’
M 最後にファイルを変更した時間
M: M と同じで、タイムスタンプの書式
C 最後に inode を変更した時間
C: C と同じで、タイムスタンプの書式
D デバイス番号
I inode 番号
F device:inode の形式で表した複合 file 識別子
L シンボリックリンクが指しているファイルの名前
N (ハード) リンクの数
P 先頭に 0 がついていない 8 進数で表したパーミッション
P: P と同じで、先頭に 0 がつく
Pmode ‘-P file & mode’ と等価。たとえば、‘-P22 file’ は file のグ
ル ープと他者が書き込み可であれば ‘22’ を、グループのみであ
れば ‘20’ を、何もなければ ‘0’ を返す。
Pmode: Pmode: と同じで、先頭に 0 がつく
U 数値で表したユーザ ID
U: ユーザ名、ユーザ名が見つからなかった場合は数値で表したユ ー
ザ ID
G 数値で表したグループ ID
G: グループ名、グループ名が見つからなかった場合は数値で表した
グループ ID
Z バイト数で表したサイズ
これらの演算子のうち 1 つだけ多重演算子の中に現れることを許されています
が 、必ず最後につける必要があります。ただし、L は多重演算子の中の最後と
それ以外の箇所では違った意味になるので注意してください。なぜな ら 、‘0’
は これらの演算子の多くにとって正当な返り値のためです。これらが失敗した
場合、‘0’ を返しません。たいていの場合、‘-1’ を返し、F は ‘:’ を返し ま
す。
こ の シェルが POSIX を定義してコンパイルされている (シェル変数 version
を参照) 場合、ファイル問い合わせの結果は、 access(2) システムコールの結
果 に基づいたものではなく、ファイルの許可ビットに基づいたものになります
。たとえば、通常は書き込み可であるが読み取り専用でマウントされたファ イ
ルシステム上にあるファイルを -w で検査した場合、 POSIX シェルでは成功し
、非 POSIX シェルでは失敗することになります。
ファイル問い合わせ演算子は filetest 組み込みコマンド (そちらも参照) と
等価になり得ます。(+)
ジョブ
シェルはパイプラインの各々に対しジョブを 1 つずつ関連付けます。シェルは
、現在実行中のジョブの一覧表を保持しており、これは、jobs コマンドによっ
て 表示することができます。ジョブには整数の番号が割り当てられます。ジョ
ブが ‘&’ を用いて非同期に起動された場合、シェルは以下のような出力を行い
ます:
[1] 1234
こ れ は 、 非同期に起動したジョブがジョブ番号 1 であり、プロセス ID が
1234 である (トップレベルの) プロセスを 1 つ持っていることを示します。
もし、あるジョブを実行中に他のことをしたくなった場合、サスペンドキー (
通常 ^Z) を押すことにより実行中のジョブに STOP シグナルを送信することが
できます。通常、シェルはそのジョブが一時停止した (Suspended) ことを出力
し 、プロンプトを表示します。シェル変数の listjobs が設定されていると、
組み込みコマンドの jobs のようにすべてのジョブがリストされます。もし そ
れが ‘long’ と設定されているとリストは ‘jobs -l’ のような長い形式になり
ます。ここで、一時停止したジョブの状態を操作することができます。つま り
、bg コマンドにより停止したプロセスを ‘‘バックグラウンド’’ で走行させた
り、他のコマンドを実行してから、停止していたジョブを fg コマンドによ り
‘‘フォアグラウンド’’ で再実行させることなどができます。 (編集コマンドの
run-fg-editor も参照してください。) ‘^Z’ は即座に効力を発揮し、割り込み
と 同様に、それまで待たされていた出力とまだ読み込まれていない入力は捨て
られます。組み込みコマンドの wait はすべてのバックグラウンドのジョブ が
終了するまでシェルを待機状態にさせます。
‘^]’ キーは遅延サスペンドシグナルを現在のジョブに送信します。この場合は
プログラムが read(2) によって読み込もうとした時点で STOP シグナルが送信
さ れます。これは、実行中のジョブに対していくつかの入力を先に入力してお
き、先行入力を読み終えた時点でジョブを停止させたいときに 便 利 で す 。
csh(1) で は この機能は ‘^Y’ キーに割り当てられていました。 tcsh では
‘^Y’ は編集コマンドです。(+)
バックグラウンドで実行しているジョブが端末からの入力を試みた場合、そ の
ジ ョブは停止します。通常、バックグラウンドジョブが端末に出力することは
可能ですが、これはコマンド ‘stty tostop’ により禁止することができます。
もしこの tty オプションを指定したなら、バックグラウンドで実行しているジ
ョブは、端末から入力を試みたときと同様に、端末に出力を試みたときに停 止
します。
シェルでジョブを参照するにはいくつかの方法があります。文字 ‘%’ はジョブ
名を表すのに用いられます。番号 1 のジョブを参照する場合は ‘%1’ とします
。 単にジョブ名を入力した場合、そのジョブはフォアグラウンドに移動されま
す。すなわち ‘%1’ は ‘fg %1’ と等価で、ジョブ 1 をフォアグラウンドに 移
行 します。同様に ‘%1 &’ は、ちょうど ‘bg %1’ と同じようにのジョブ 1 を
バックグラウンドで再開させます。ジョブはそのジョブを起動したときにタ イ
プ された文字列の先頭部分によって参照することもできます。ただしこの先頭
部分はあいまいでない必要があります。すなわち ‘%ex’ は、‘ex’ という文 字
列で始まる名前のサスペンドされたジョブが 1 つしかない場合に限り、サスペ
ンドされた ex(1) のジョブを再開します。文字列 string を含むジョブ が 1
つしかない場合、‘%?string’ と入力することでそれを指定することもできます
。
シェルは現在のジョブと直前のジョブを覚えています。ジョブに関係する出 力
で、‘+’ 記号が付加されているのが現在のジョブ、 ‘-’ 記号が付加されている
のが直前のジョブです。 ‘%+’, ‘%’ と (ヒストリ機構の文法との類 似 か ら)
‘%%’ はすべて現在のジョブ、‘%-’ は直前のジョブを参照するための省略形で
す。
ある種のシステムではジョブ制御機構を利用するために stty(1) のオプション
‘new’ を設定しておく必要があります。ジョブ制御機構は ‘新型の’ 端末ドラ
イバの実装の上に構築されているからで、新型の端末ドライバによりジョブ を
停 止させるための割り込み文字をキーボードから入力できるようになるからで
す。新型の端末ドライバのオプション設定については stty(1) と組み込みコマ
ンドの setty を参照してください。
状態通知
シ ェルは、プロセスが状態の変化を起こすとすぐにそれを検知します。通常は
プロンプトが表示される直前にのみ、あるジョブが停止してそれ以上処理が 進
ま なくなったことを通知します。これはユーザの仕事を邪魔しないようにする
ためです。しかしながら、シェル変数 notify を設定することにより、シェ ル
に バックグラウンドジョブの状態が変化したことをただちに通知させることが
できます。また、シェルコマンド notify により、特定のジョブの状態の変 化
を た だちに通知させるようにマークすることもできます。引数なしの notify
は現在のプロセスに対してマークをつけます。バックグラウンドジョブの開 始
直後に単に ‘notify’ と打つとそのジョブをマークします。
停 止 し た ジ ョブが存在する状態でシェルを終了しようとすると ‘You have
stopped jobs.’ という警告を受けます。このとき jobs コマンドによりどのジ
ョブが停止中であるのかを確認することができます。警告を受けた直後に jobs
コマンドで確認した場合と、警告を受けた直後に再度シェルを終了させよう と
した場合には、シェルは 2 度目の警告を行わずに停止中のジョブを終了させて
からシェルを終了します。
自動イベント、定期イベント、時刻指定イベント (+)
シェルの ‘‘ライフサイクル’’ において、いろいろな時間に自動的にコマン ド
の 実行と他のアクションを行うさまざまな方法が用意されています。それらを
ここに要約し、詳しくは組み込みコマンド、特別なシェル変数、特別なエイ リ
アスの適切な場所で説明します。
組み込みコマンドの sched はコマンドをイベントの予定表に置き、指定された
時刻にシェルによって実行されるようにします。
特別なエイリアスとして beepcmd, cwdcmd, periodic, precmd, postcmd,
jobcmd があり、それぞれシェルがベルを鳴らす時、作業ディレクトリが変わる
時、 tperiod 分毎、各プロンプトの前、各コマンドの実行前、各コマンドの実
行 後、ジョブの起動時またはフォアグラウンド移行時に実行させたいコマンド
を設定できます。
シェル変数の autologout を使って、指定した分数の休止後にログアウトま た
はシェルをロックするように設定できます。
シ ェル変数の mail を使って、定期的に新しいメールをチェックするように設
定できます。
シェル変数の printexitvalue を使って、0 以外のステータスで終了したコ マ
ンドの終了ステータスを表示するように指定できます。
シェル変数の rmstar を使って、‘rm *’ が入力されたときにユーザに間違いな
いかどうか確認を求めるように指定できます。
シェル変数の time を使って、指定した秒数より多く CPU 時間を使ったプロセ
スの終了後に組み込みコマンドの time を実行するように設定できます。
シ ェル変数の watch と who を使って、指定したユーザがログインまたはログ
アウトした時にレポートするように設定できます。また組み込みコマ ン ド の
log でいつでもそれらのユーザについてのレポートを得られます。
固有言語システムのサポート (+)
シェルは 8 ビットクリーンなので (そのようにコンパイルされていれば。シェ
ル変数の version を参照)、それを必要とする文字セットをサポートします 。
NLS サポートはシェルがシステムの NLS を使うようにコンパイルされているか
どうかによって異なります (再び、version を参照)。どちらの場合でも 7 ビ
ット ASCII がデフォルトの文字分類 (たとえばそれらの文字は表示可能) であ
り、そして順序づけです。環境変数の LANG または LC_CTYPE を変更すると 、
これらの点について変化の有無がチェックされます。
システムの NLS を使う場合には、文字の適切な分類と順序づけを決定するため
に setlocale(3) 関数が呼び出されます。この関数は典型的には環境 変 数 の
LANG と LC_CTYPE を調べます。より詳細についてはシステムのドキュメントを
参照してください。システムの NLS を使わない場合には 、 シ ェ ル は ISO
8859-1 文字セットが使われていると仮定することでシミュレートします。変数
LANG と LC_CTYPE のいずれかが設定されていても、それらの値を無視します。
シミュレートされた NLS では順序づけに影響しません。
加えて、本物とシミュレートされた NLS の両方で、\200-\377 の範囲、つまり
M-char でバインドされているすべての表示可能文字は 、 自 動 的 に self-
insert-command に再バインドされます。対応する escape-char へのバインド
は、もしあればそのまま残ります。これらの文字は環境変数の NOREBIND が 設
定されていれば再バインドされません。この機能はシミュレートされた NLS や
すべてが ISO 8859-1 であると仮定した原始的な本物の NLS で有効でしょう。
そ うでなければ、\240-\377 の範囲の M-char へのバインドは事実上解除され
ます。この場合でも、もちろん bindkey で明示的に関連するキーに再バインド
する事は可能です。
未 知の文字 (つまり表示可能でも制御文字でもないような文字) は \nnn のよ
うな形式で表示されます。tty が 8 ビットモードになって い な い 場 合 は
、ASCII に変換して強調表示モードを使うことで別の 8 ビット文字が表示され
ます。シェルは tty の 7/8 ビットモードを変更することはなく、ユーザに よ
る 7/8 ビットモードの変更に従います。NLS 利用者 (またはメタキーを利用し
たい利用者) は、たとえば ~/.login ファイルで適切に stty(1) コマンドを呼
び 出すことで、明示的に tty を 8 ビットモードに設定する必要があるかもし
れません。
OS 固有機能のサポート (+)
個々のオペレーティングシステムで提供されている機能をサポートするため に
、 多くの新しい組み込みコマンドが提供されています。すべて組み込みコマン
ドセクションで詳細に説明されています。
TCF をサポートするシステム (aix-ibm370, aix-ps2) では 、 getspath と
setspath でシステム実行パスを取得、設定し、 getxvers と setxvers で試験
バージョンプリフィックスを取得、設定して、migrate でプロセスをサイト 間
で 移動させます。組み込みコマンドの jobs は各ジョブが実行されているサイ
トを表示します。
Domain/OS では、inlib で共有ライブラリを現環境に追加し、 rootnode で
rootnode を変更し、ver で systype を変更します。
Mach では、setpath が Mach の setpath(1) と等価です。
Masscomp/RTU と Harris CX/UX では、universe で universe を設定します。
Harris CX/UX では、ucb か att によって指定した universe でコマンドを走
らせます。
Convex/OS では、warp で universe を表示または設定します。
環境変数の VENDOR, OSTYPE, MACHTYPE は、シェルが自身が実行されている と
考 えているシステムの、それぞれベンダー、オペレーティングシステム、マシ
ンタイプ (マイクロプロセッサのクラスまたはマシンのモデル) を表示しま す
。 これはいろいろなタイプのマシン間でホームディレクトリを共有する場合に
特に便利です。利用者はたとえば各自の ~/.login 中で
set path = (~/bin.$MACHTYPE /usr/ucb /bin /usr/bin .)
とし、各マシン用にコンパイルされた実行形式を適切なディレクトリに置く こ
とができます。
シェル変数の version は、どのオプションを選択してシェルがコンパイルされ
たかを表示します。
組み込みの newgrp、シェル変数の afsuser と echo_style、そしてシステムに
依 存するシェルの入力ファイル (ファイルを参照) の位置にも注意してくださ
い。
シグナル処理
ログインシェルは ~/.logout ファイルを読んでいる間は割り込みを無視します
。 シェルは起動時に -q の指定が無ければ QUIT シグナルを無視します。ログ
インシェルは TERM シグナルを捕捉しますが、非ログインシェルは TERM シ グ
ナ ルへの挙動を親から継承します。他のシグナルについては親からシェルに継
承された値を持っています。
シェルスクリプトでは、シェルの INT と TERM シグナルの扱いを onintr で制
御できます。そして HUP の扱いを hup と nohup で制御できます。
シ ェルは HUP で終了します (シェル変数の logout も参照)。デフォルトでは
、シェルの子供たちもそうしますが、シェルは終了時に HUP を子供たちに送り
ません。hup はシェルが終了時に子供に HUP を送るようにし、nohup は子供が
HUP を無視するように設定します。
端末管理 (+)
シェルは 3 つの異なる端末 (‘‘tty’’) モードの設定を使います。それらは 編
集時に使う ‘edit’、文字リテラルをクォートする場合に使う ‘quote’、コマン
ド実行時に使う ‘execute’ です。シェルは各モードでいくつかの設定を一定に
保つので、 tty を混乱状態にして終了するコマンドがシェルに干渉することは
ありません。シェルは tty のスピードとパディングの変更にも対応します。一
定 に保たれる tty モードのリストは組み込みの setty で取得、設定できます
。エディタは CBREAK モード (または同等のモード) を使いますが、先行入 力
された文字はいつでも受け付けられます。
echotc, settc, telltc コマンドを使って、コマンドラインから端末のケーパ
ビリティを操作、デバッグすることができます。
SIGWINCH か SIGWINDOW をサポートするシステムでは、シェルはウィンドウ の
リ サイズに自動的に適応して、環境変数の LINES と COLUMNS が設定されてい
れば値を補正します。環境変数の TERMCAP が li# と co# のフィールドを含ん
で いると、シェルは新しいウィンドウサイズを反映するようにそれらを補正し
ます。
参照
このマニュアルの以下のセクションでは使用可能なすべての組み込みコマン ド
、特別なエイリアス、特別なシェル変数について説明します。
組み込みコマンド
%job 組み込みコマンド fg と同義です。
%job & 組み込みコマンド bg と同義です。
: 何もしません。常に成功します。
@
@ name = expr
@ name[index] = expr
@ name++|--
@ name[index]++|--
最初の形式は、すべてのシェル変数の値を表示します。
2 番目の書式は、name に値 expr を設定します。 3 番目の書式は、
値 expr を name の index 番目の要素に定義します。 name と そ の
index 番目の要素の両方が既に存在していなければなりません。
expr は C と同様に、‘*’, ‘+’のような演算子を含むことがあります
。もし expr が ‘<’, ‘>’, ‘&’, ‘’ を含むのであれば、少なく と も
expr のその部分は ‘()’ の中に書かれる必要があります。 expr の書
式は、以下の Expressions で説明されるものとは一切関係がないこと
に注意してください。
4 番目、5 番目の書式は name またはその index 番目の要素をインク
リメント (‘++’) またはデクリメント (‘--’) します。
‘@’ と name の間の空白は必須です。name と ‘=’ の間、また ‘=’ と
expr の間の空白はオプションです。expr の要素は空白によって区切
られていなければなりません。
alias [name [wordlist]]
引数がなければ、すべてのエイリアスを表示します。 name を与え る
と 、そのエイリアスの内容を表示します。 name と wordlist を与え
ると、 wordlist を name のエイリアスとして定義します。 wordlist
は 、エイリアスされるコマンドとファイル名です。 name は ‘alias’
または ‘unalias’ であってはなりません。組み込みコマンド unalias
についても参照してください。
alloc 動的に取得しているメモリのうちの使用量と空き容量を表示します。
何らかの引数を与えるとブロックサイズごとの使用中 / 空きブロック
の 数を表示します。このコマンドの出力はシステムによって大きく異
なります。 VAX 以外のシステムでは、異なるメモリ管理を行っている
かもしれないからです。
bg [%job ...]
指 定したジョブ (引数がなければ現在のジョブ) をバックグラウンド
に移動します。もしそれらが停止していれば再開されます。job は 以
下 の Jobs で説明するように番号、文字列、‘’, ‘%’, ‘+’, ‘-’ で構
成されます。
bindkey [-l|-d|-e|-v|-u] (+)
bindkey [-a] [-b] [-k] [-r] [--] key (+)
bindkey [-a] [-b] [-k] [-c|-s]
[--] key command (+) オプション無しでは、第 1 の形式ではバイ ン
ドされているすべてのキーと編集コマンドを表示し、第 2 の形式では
key にバインドされている編集コマンドを表示し、第 3 の形式では編
集 コマンド command を key にバインドします。オプションは以下の
ものを含みます。
-l すべての編集コマンドの一覧と、それぞれの簡単な解説を表示 し
ます。
-d デフォルトのエディタの標準キーバインドをすべてのキーに適用
します。
-e GNU Emacs に似たキーバインドをすべてのキーに適用します。
-v 標準の vi(1) に似たキーバインドをすべてのキーに適用します。
-a 代替キーマップを表示またはそのキーバインドを変更します。代
替キーマップは vi コマンドモードのものです。
-b key を次のように解釈します。 ^character (たとえば ‘^A’)、C-
character (たとえば ‘C-A’) のようなものはコントロールキャラ
クタ、 M-character (たとえば ‘M-A’)のようなものはメタキャラ
クタ、 F-string (たとえば ‘F-string’)のようなものはファンク
ションキー、X-character (たとえば ‘X-A’) のようなものは拡張
プリフィックスキーです。
-k key は矢印キーの名前、‘down’, ‘up’, ‘left’, ‘right’ のいず
れかとして解釈されます。
-r key のバインドを解除します。 ‘bindkey -r’ は key を self-
insert-command にバインドするのではなく、そのキーのバインド
を完全に解除してしまうことに注意してください。
-c command は編集コマンドでなく、組み込みコマンドか外部コマ ン
ドの名前として解釈されます。
-s command は通常の文字列として解釈され、key がタイプされた時
に端末から入力されたように扱われます。command でバインド さ
れたキー自体も再び解釈が行われ、10 レベルまで繰り返し解釈が
行われます。
-- オプション処理の中断を行います。したがって、次の単語が ’-’
で始まっていたとしても、key として解釈されます。
-u (または何らかの無効なオプション)
使い方を表示します。
key は 1 文字であっても、文字列であっても構いません。もしコマン
ドが文字列にバインドされているならば、文字列の最 初 の 文 字 は
sequence-lead-in にバインドされ、文字列全体がコマンドにバインド
されます。
key に含まれるコントロール文字はコントロール文字そのもの (通 常
‘^V’ にバインドされているエディタの quoted-insert コマンドで入
力できるもの) であっても、‘^A’ のようなキャレット-文字形式で あ
っ ても構いません。削除文字は ‘^?’ (キャレット-疑問符) のように
表します。key と command は下に示す、バックスラッシュで始まるエ
ス ケープシーケンスを含むことができます (System V の echo(1) で
用いられる形式です)。
\a ベル
\b バックスペース
\e エスケープ
\f 改ページ (フォームフィード)
\n 改行
\r キャリッジリターン
\t 水平タブ
\v 垂直タブ
\nnn 8 進数 nnn で表されるアスキー文字
‘\’ は後に続く文字に特別な意味があればそれを無効にします。特 に
‘\’ や ‘^’ の場合です。
break 実行を一番近い foreach または while と end の組の、end の後から
再開します。現在の行の残りのコマンドは実行されます。したがっ て
、 複数のレベルのブレークは、1 行にそれらを並べることで可能にな
ります。
breaksw switch からのブレークで、endsw の後から実行が開始されます。
builtins (+)
すべての組み込みコマンドの名前を表示します。
bye (+) 組み込みコマンド logout の別名です。これが使えるようにコンパ イ
ルされている場合にのみ有効です。シェル変数 version を参照してく
ださい。
case label:
下で説明する switch 文で用いられるラベルです。
cd [-p] [-l] [-n|-v] [name]
もしディレクトリ名 name が与えられれば、シェルの作業ディレク ト
リ を name に変更します。与えられなければ home に変更します。も
し name が ‘-’ であれば、ひとつ前の作業ディレクトリとして解釈さ
れ ます (Other substitutions を参照)。name が現在のディレクトリ
のサブディレクトリでなく、 ‘/’, ‘./’ , ‘../’ のいずれかで始まる
も のでもない場合、変数 cdpath の要素がひとつひとつチェックされ
、サブディレクトリ name が探されます。最後に、そのどれもが失 敗
した場合に name が ‘/’ ではじまる値をもつシェル変数であれば、そ
の変数が指すディレクトリが探されます。
-p を付けると、dirs と同じように最終的なディレクトリスタック の
内容を表示します。cd の -l, -n, -v フラグは dirs のそれと同じ意
味を持ち、 -p の動作を含んでいます (+)。
シェル変数 implicitcd についても参照してください。
chdir 組み込みコマンド cd の別名です。
complete [command
[word/pattern/list[:select]/[[suffix] /] ...]] (+) 引数なしの場
合は、すべての補完の候補を表示します。 command をつけると、com-
mand の補完候補を表示します。 command と word などをつけると 、
補完を定義します。
command はコマンドのフルネームでも、何らかのパターンでも構いま
せん (ファイル名置換を参照)。補完候補がひとつでないことを示すた
めに、‘-’ ではじめることができます。
word は現在の語の補完にどの単語が関係するのかを指定するもので、
以下のうちどれか 1 つです。
c 現在の語の補完。 pattern は、コマンドライン上の現在の語
にマッチするパターンでなければなりません。 pattern は現
在の語の補完が完了すると無視されます。
C c に似ていますが、現在の語の補完後に pattern を含みます
。
n 次の語の補完。 pattern はコマンドライン上のひとつ前の語
にマッチするパターンでなければなりません。
N n に似ていますが、現在の語のふたつ前の語にマッチする パ
ターンでなければなりません。
p 位置に依存した補完。 pattern は数値の範囲を指定するもの
であり、シェル変数のインデックスと同じ文法が用いられ ま
す。現在の語を含むものでなければなりません。
list は以下のリストの中から可能な補完のリストを示します。
a エイリアス
b バインディング (編集コマンド)
c コマンド (組み込みコマンドも外部コマンドも含みます)
C 指定されたパスではじまる外部コマンド
d ディレクトリ
D 指定されたパスではじまるディレクトリ
e 環境変数
f ファイル名
F 指定されたパスではじまるファイル名
g グループ名
j ジョブ
l 制限値
n 何にも補完しません
s シェル変数
S シグナル
t プレイン (‘‘テキスト’’) ファイル
T プレイン (‘‘テキスト’’) ファイルで、指定されたパ ス
ではじまるもの
v すべての変数
u ユーザ名
x n に似ていますが、list-choices が使われている時には
select を表示します。
X 補完
$var 変数 var に格納されている語
(...) リスト中の語
‘...‘ コマンドの出力に含まれる語
select は glob パターンです (省略可能)。これを指定すると 、list
に ある単語のうち select にマッチするものだけが対象となり、シェ
ル変数 fignore は無視されます。最後の 3 つの補完形式には select
パターンを与えることはできません。また x は list-choices 編集コ
マンドが用いられた時には select を説明メッセージとして扱いま す
。
suffix は単一の文字で、補完が成功するとそのあとに追加されます。
空の場合は何も追加されません。省略されると (この場合 4 番目のデ
リ ミタも省略できます) ディレクトリにはスラッシュ文字が、その他
の文字にはスペース文字が追加されます。
ではいくつか例を示します。コマンドによっては、ディレクトリの み
を 引 数として取るものがあります。 (そのようなコマンドに対して)
通常ファイルを補完することは、的外れです。
> complete cd ’p/1/d/’
‘cd’ に続く最初の単語のみ (‘p/1’) をディレクトリで補完します 。
コマンド補完を絞りこむために p-形式の補完を用いることもできます
。 ‘cd’ に続く最初の単語のみ (‘p/1’) をディレクトリで補完します
。
> co[^D]
complete compress
> complete -co* ’p/0/(compress)/’
> co[^D]
> compress
これは ‘co’ で始まる (すなわち ‘co*’ にマッチする) コマンド (位
置 0 にある単語 ‘p/0’) を補完して、 ‘compress’ (リストにある 唯
一の単語) を与えたものです。先頭にある ‘-’ は、この補完がコマン
ドを確定できない場合にのみ用いられることを意味します。
> complete find ’n/-user/u/’
これは n-形式の補完の例です。 ‘find’ の後で、かつ ‘-user’ の 直
後にある単語を、ユーザーのリストで補完します。
> complete cc ’c/-I/d/’
c-形式の補完の例です。‘cc’ の後にあり、かつ ‘-I’ ではじまる単語
をディレクトリで補完します。ここでは小文字の c を用いているので
、 ‘-I’ はディレクトリの一部とはみなされません。
コマンドに応じて、便利な list も異なります。
> complete alias ’p/1/a/’
> complete man ’p/*/c/’
> complete set ’p/1/s/’
> complete true ’p/1/x:Truth has no options./’
こ れらでは、 ‘alias’ に続く単語をエイリアスで、 ‘man’ に続く単
語をコマンドで、 ‘set’ に続く単語をシェル変数で置き換えています
。 ‘true’ はオプションを取らないので、補完が試みられたときに何
も行わず、補完リストの選択画面には ‘Truth has no options.’ を表
示する x を指定しています。
man の例や、以下に示すいくつかの例では、 ‘p/*’ の代わりに ‘c/*’
や ‘n/*’ を用いることもできます。
単語の補完を変数で行うこともできます。これらの変数は補完の際 に
評価されます。
> complete ftp ’p/1/$hostnames/’
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu
> ftp [^C]
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu
uunet.uu.net)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net
また補完の際にコマンドを実行し、そこから補完を行うこともでき ま
す。
> complete kill ’p/*/‘ps | awk \{print\ \$1\}‘/’
> kill -9 [^D]
23113 23377 23380 23406 23429 23529 23530 PID
complete コマンド自身は、その引数をクォートしません。したがって
‘{print $1}’ にある括弧、スペース、‘$’ は明示的にクォートしなけ
ればなりません。
1 つのコマンドに複数の補完を指定することもできます。
> complete dbx ’p/2/(core)/’ ’p/*/c/’
こ れは ‘dbx’ の第 2 引数を ‘core’ という単語で補完し、他のすべ
ての引数をコマンドで補完します。位置指定タイプの補完は、逐次 補
完 より前に指定することに注意してください。補完は左から右に評価
されるので、 (常にマッチする) 逐次補完が先に指定されていると 、
位 置指定補完は決して行われなくなってしまいます。これは補完定義
の際によくやるミスなので注意してください。
select パターンは、コマンドが特定の形式を持ったファイルだけを引
数にとるような場合に便利です。以下に例を示します。
> complete cc ’p/*/f:*.[cao]/’
これは ‘cc’ の引数を、‘.c’, ‘.a’, ‘.o’ で終わるファイルだけから
補完します。以下のファイル名置換で述べるようなやり方でグロブ パ
タ ーンの否定を指定すれば、 select で特定のファイルを排除するこ
ともできます。
> complete rm ’p/*/f:^*.{c,h,cc,C,tex,1,man,l,y}/’
これは大事なソースコードを ‘rm’ の補完に現れないようにします 。
もちろんこの排除された名前を手で打ったり、 complete-word-raw や
list-choices-raw などの編集コマンドを用いて補完の仕組みを変更す
ることもできます (それぞれ該当の部分を参照)。
‘C’, ‘D’, ‘F’, ‘T’ 各リストは、それぞれ ‘c’, ‘d’, ‘f’, ‘t’ と似
ていますが、 select の引数の解釈の仕方が異なり、補完対象のフ ァ
イ ルを前置パス名が特定のものに限ります。たとえば、メールプログ
ラム Elm は ‘=’ をユーザのメールディレクトリの省略名として用 い
ま す。この場合 ‘elm -f =’ を ‘elm -f ~/Mail/’ であるかのように
補完するには
> complete elm c@=@F:$HOME/Mail/@
とすべきです。ここでは ‘/’ の代わりに ‘@’ を用い、 select 引 数
を 見やすくしています。またホームディレクトリの置換は単語の先頭
でのみ動作するので、 ‘~’ の代わりに ‘$HOME’ を用いています。
suffix は標準では用意されていないサフィックス (スペースやディレ
クトリに対する ‘/’ 以外) を単語補完用に追加するために用います。
> complete finger ’c/*@/$hostnames/’ ’p/1/u/@’
これは ‘finger’ の引数を、まずユーザのリストから補完し、それ に
‘@’ を追加し、さらに ‘@’ の後を変数 ‘hostnames’ のリストから補
完します。ここでも補完指定の順序に注意してください。
最後に、示唆に富む複雑な例を示しましょう。
> complete find \
´n/-name/f/’ ’n/-newer/f/’ ’n/-{,n}cpio/f/’ \
´n/-exec/c/’ ’n/-ok/c/’ ’n/-user/u/’ \
´n/-group/g/’ ’n/-fstype/(nfs 4.2)/’ \
´n/-type/(b c d f l p s)/’ \
´c/-/(name newer cpio ncpio exec ok user \
group fstype type atime ctime depth inum \
ls mtime nogroup nouser perm print prune \
size xdev)/’ \
´p/*/d/’
これは ‘-name’, ‘-newer’, ‘-cpio’, ‘ncpio’ に続く単語をファイル
で 補 完 し ( 最後の両者にマッチするパターンに注意)、 ‘-exec’,
‘-ok’ に続く単語をコマンドで補完し、 ‘user’ の後をユー ザ 名 で
、‘group’ の後をグループ名で補完し、 ‘-fstype’ と ‘-type’ の後
をそれぞれに与えたリストのメンバーで補完します。また find に 与
え るスイッチ達も与えたリストから補完し (c-型の補完を用いている
ことに注意)、それ以外のものすべてをディレクトリで補完します。ふ
ぅ。
補 完指定は、対象となる単語がチルダ置換 (‘~’ ではじまる) や変数
(‘$’ ではじまる) の場合は無視されることに留意してく だ さ い 。
complete は実験的な機能であり、文法はこのシェルの将来のバージョ
ンでは変更されるかもしれません。組み込みコマンド uncomplete の
説明も見てください。
continue
も っとも近い while または foreach ループの実行を継続します。現
在の行にある残りのコマンドは実行されます。
default:
switch 文のデフォルトの場合のラベルです。これはすべての case ラ
ベルの後に置くべきです。
dirs [-l] [-n|-v]
dirs -S|-L [filename] (+)
dirs -c (+)
最 初の形式はディレクトリスタックを表示します。スタックの上が左
に来て、スタック先頭のディレクトリは現在のディレクトリになり ま
す 。 -l を指定すると、出力の ‘~’ や ‘~name’ は、 home や、ユー
ザ name のホームディレクトリのパス名に明示的に展開され ま す 。
(+) -n を指定すると、エントリはスクリーンの終端に達する前に桁折
りされます。 (+) -v を指定すると、各エントリが 1 行に 1 つず つ
表 示 さ れ、スタック内部での位置がエントリの前に表示されます。
(+) -n や -v がひとつ以上指定されると -v が優先されます。
-S を指定した 2 番目の形式では、ディレクトリスタックを cd と
pushd からなるコマンド列として filename に保存します。 -L を指
定すると、このシェルは filename を source します。このファイ ル
は 、以前に -S オプションや savedirs 機構で保存されたディレクト
リスタックです。いずれの場合でも、 filename が与えられなけれ ば
dirsfile を 用 い ま す 。 dirsfile も指定されていなければ
~/.cshdirs を用います。
ログインシェルは ‘dirs -L’ と同様のことを起動時に行っており、ま
た savedirs が設定されていれば終了前に ‘dirs -S’ と同様のことを
行います。通常 ~/.tcshrc だけが ~/.cshdirs の前に source される
ので、 dirsfile は ~/.login ではなく ~/.tcshrc で設定すべきです
。
最後の形式はディレクトリスタックをクリアします。
echo [-n] word ...
各 word をスペースで区切り、改行で終端させてシェルの標準出力 に
書 き出します。シェル変数 echo_style を指定すると、 BSD や Sys-
tem V の echo のフラグやエスケープシーケンスをエミュレートす る
(しない) ようにできます。詳細は echo(1) を見てください。
echotc [-sv] arg ... (+)
arg で与えられた端末の機能 (termcap(5) を参照) を実行します。た
とえば ‘echotc home’ はカーソルをホームポジションに 移 動 し 、
‘echotc cm 3 10’ はカーソルを 3 列 10 行に移動し、 ‘echotc ts
0; echo "This is a test."; echotc fs’ は "This is a test." をス
テータス行に表示します。
arg が ‘baud’, ‘cols’, ‘lines’, ‘meta’, ‘tabs’ のいずれかであっ
た場合は、その機能の値を表示します ("yes" または "no" は、端 末
がその機能を持っているかいないかを示します)。遅い端末でシェルス
クリプトの出力をより寡黙にしたり、コマンドの出力をスクリーン の
行 数に制限したりするような場合には、以下のコマンドを使うと良い
でしょう。
> set history=‘echotc lines‘
> @ history--
termcap 文字列はワイルドカードを含むことができますが、これは 正
し く echo されません。シェル変数に端末機能文字列を設定するとき
には、以下の例のようにダブルクォートを用いてください。この例 で
は日付をステータス行に表示しています。
> set tosl="‘echotc ts 0‘"
> set frsl="‘echotc fs‘"
> echo -n "$tosl";date; echo -n "$frsl"
-s を指定すると、存在しない機能を指定したとき、エラーをおこさず
に空文字列を返します。 -v を指定するとメッセージが冗長になり ま
す。
else
end
endif
endsw 以下の foreach, if, switch, while 文の説明を見てください。
eval arg ...
引 数をシェルへの入力として扱い、残りのコマンドを現在のシェルの
コンテキストで実行します。これは通常、コマンド置換や変数置換 の
結 果として生成されたコマンド列を実行する場合に用いられます。こ
れはそれらの置換に先立って文法解析が行われてしまうため で す 。
eval の利用例は tset(1) を見てください。
exec command
指定したコマンドを現在のシェルの代わりに実行します。
exit [expr]
指 定した expr (式で解説した式) の値で (expr が指定されていなけ
れば status 変数の値で) シェルを終了します。
fg [%job ...]
指定したジョブ (あるいは引数がなければ現在のジョブ) をフォア グ
ラウンドに移動します。停止状態にあるものは再開します。 job には
ジョブで解説されているように、数値、文字列、‘’, ‘%’, ‘+’, ‘-’
のどれかを指定できます。 run-fg-editor 編集コマンドも見てくださ
い。
filetest -op file ... (+)
(ファイル問合わせ演算子で解説されている) ファイル問合わせ演算子
op を各 file に適用し、結果をスペース区切りのリストで返します。
foreach name (wordlist)
...
end wordlist のメンバーを name に順々に代入し、これと対応す る end
に 挟 ま れた範囲のコマンドシーケンスを実行します。 (foreach と
end は 1 行に単独で現れなければなりません。) 組み込みコマ ン ド
continue を用いるとループを途中で継続することができ、組み込みコ
マンド break を用いるとループを途中で終了させることができます。
こ の コマンドが端末から読み込まれると、一度ループを ‘foreach?’
プロンプト (あるいは prompt2) で読み込み、全体を読み終えてか ら
ル ープの各文を実行します。端末からの入力時にループの途中でタイ
プミスをした場合は修正できます。
getspath (+)
システムの実行パスを表示します。 (TCF のみ)
getxvers (+)
実験的バージョンのプレフィックスを表示します。 (TCF のみ)
glob wordlist
echo と似ていますが、‘\’ でのエスケープを認識せず、また出力での
単 語区切りをヌル文字にします。単語リストをファイル名に展開する
ためにプログラムからシェルを利用したいような場合に便利です。
goto word
word はファイル名と ‘label’ 形式の文字列を出力するコマンド置 換
で す。シェルは入力を可能なかぎりさかのぼり、 ‘label:’ 形式の行
(空白やタブが前置されていても良い) を検索し、その行の次から実行
を継続します。
hashstat
内 部のハッシュテーブルが、これまでのコマンド探索にどの程度効率
的であったか (そして exec 類を使わずに済んだか) を示す統計行 を
表 示します。 path の各成分のうち、ハッシュ関数がヒットの可能性
があるとしたものや、 ‘/’ で始まらないものに対して exec が試みら
れます。
vfork(2) のないマシンでは、単にハッシュバケツのサイズを表示しま
す。
history [-hTr] [n]
history -S|-L|-M [filename] (+)
history -c (+)
最初の形式はイベントリストの履歴を表示します。 n を与えると、新
しい方最大 n 個のイベントを表示または保存します。 -h を指定する
と、行頭の数字抜きでリストを表示します。 -T を指定すると、タ イ
ム スタンプもコメントのかたちで表示されます。 (これを用いると、
‘history -L’ や ‘source -h’ でのロードに適したファイルが作成 で
きます。) -r を指定すると、表示の順番がデフォルトの古い順ではな
く新しい順になります。
2 番目の形式で -S を指定すると、履歴リストを filename に保存 し
ま す。シェル変数 savehist の最初の単語が数値に設定されていると
、最大でその数値までの行数が保存されます。 savehist の 2 番目の
単語が ‘merge’ だった場合には、履歴リストが現存の履歴ファイルに
マージされ、タイムスタンプ順にソートされます (デフォルトでは 現
存のファイルを置き換えます)。 (+) マージは X Window System のよ
うに、複数のシェルを同時に用いるような場合向けのものです。現 在
は 、シェルが行儀良く順々に終了するような場合でないと、マージは
成功しません。
-L を指定すると、シェルは filename を履歴リストに追 加 し ま す
。filename は以前に -S オプションや savehist 機構で保存された履
歴リストファイルです。 -M は -L と似ていますが、 filename の 内
容 は履歴リストにマージされ、タイムスタンプの順にソートされます
。いずれの場合でも、filename が与えられなければ histfile を用い
、 histfile も 設 定されていなければ ~/.history を用います。
‘history -L’ はほとんど ‘source -h’ と同じですが、前者ではフ ァ
イル名を省略できます。
ロ グインシェルは ‘history -L’ と同様のことを起動時に行っており
、また savehist が設定されていれば終了前に ‘history -S’ と同 様
の こ と を 行 い ます。通常 ~/.tcshrc だけが ~/.history の前に
source されるので、 histfile は ~/.login ではなく ~/.tcshrc で
設定すべきです。
histlit が設定されていると、最初の形式と 2 番目の形式は履歴リス
トを文字通りの (展開されない) かたちで表示、保存します。
最後の形式は履歴リストをクリアします。
hup [command] (+)
command を指定すると、 hangup シグナルが送られたときに終了す る
ようにして command を実行し、シェルが終了するときにそのコマンド
に hangup シグナルを送るようにします。コマンドによっては hangup
に対するそれぞれ独自の反応を設定することがあり、これは hup より
優先されるかもしれません。引数を設定しないと (シェルスクリプ ト
内 部 の み で許されます)、そのシェルは残りのスクリプトの途中で
hangup シグナルを受け取ると終了するようになります。シグナル処理
と組み込みコマンド nohup の部分も見てください。
if (expr) command
expr (式で解説した式) の評価結果が真なら、 command が実行されま
す。 command に対する変数置換は、実行に先だって if コマンドの残
りの部分と同時に行われます。 command は単純なコマンドでなければ
ならず、エイリアス、パイプライン、(括弧で括られた / てい な い)
コマンドリストは指定できません。ただし引数は指定できます。 expr
が偽で、 command が実行されない場合でも入出力リダイレクションは
行われてしまいます。これはバグです。
if (expr) then
...
else if (expr2) then
...
else
...
endif 指定した expr が真の場合、最初の else までのコマンド群が実行さ
れます。 expr が偽で expr2 が真の場合は、 2 番目の else まで の
コマンド群が実行されます。以下同じです。 else-if のペアはいくつ
でも指定できますが、 endif はひとつしかいりません。また else 部
は 省略可能です。 (else と endif の各単語は入力行の先頭にしか置
けません。 if は入力行の先頭に単独で置くか、 else の後に置く か
しなければなりません。)
inlib shared-library ... (+)
各 shared-library を現在の環境に追加します。共有ライブラリを削
除する方法はありません。 (Domain/OS のみ)
jobs [-l]
アクティブなジョブをリストします。 -l を指定すると、通常の情 報
に加えてプロセス ID もリストします。 TCF システムでは、各ジョブ
が実行されているサイトも表示します。
kill [-s signal] %job|pid ...
kill -l 1 番目または 2 番目の形式は signal を (何も指定され な け れ ば
TERM (terminate) シグナルを) 指定したジョブやプロセスに送ります
。 job にはジョブで解説されているように、数値、文字列、‘’, ‘%’,
‘+’, ‘-’ の ど れ かを指定できます。シグナルは数値または名前
(/usr/include/signal.h にあるものから前の ‘SIG’ を取り除いた も
の) のいずれかで与えます。デフォルトの job はありません。単に
‘kill’ としても、現在のジョブへはシグナルを送りませ ん 。 TERM
(terminate) または HUP (hangup) シグナルを送った場合は、そのジ
ョブやプロセスには CONT (continue) シグナルも送信されます 。 3
番目の形式はシグナルの名前をリストします。
limit [-h] [resource [maximum-use]]
現 在のプロセスと、現在のプロセスが生成するプロセスが消費する資
源が、指定した resource に対してプロセスひとつにつ き maximum-
use を越えないようにします。 maximum-use を指定しないと、cur-
rent limit が表示されます。 resource を指定しないと、すべての制
限値を表示します。 -h フラグを指定すると、 current limit の代わ
りに hard limit を用います。 hard limit は current limit の限度
を 与えます。 hard limit はスーパーユーザーしか増やすことができ
ませんが、 current limit は一般ユーザも可能な範囲内で増減できま
す。
現 在制御できる資源は、 cputime (プロセスひとつにつき利用できる
cpu 秒)、 filesize (作成できる単一ファイルの最大サイズ)、 data-
size (プログラムテキストの終端を越えて sbrk(2) で増やせるデータ
領域+スタック領域の最大サイズ)、 stacksize (自動的に拡張され る
ス タック領域の最大サイズ)、 coredumpsize (生成されるコアダンプ
の最大サイズ)、 memoryuse (プロセスひとつにいちどきに割り当てる
ことのできる物理メモリの最大サイズ)、です。
maximum-use は浮動小数点値または整数値に、単位をつけて指定しま
す。 cputime 以外の制限値は、‘k’ または ‘kilobytes’ (1024 バ イ
ト) を デ フ ォ ルトの単位としています。単位として ‘m’ または
‘megabytes’ を用いることもできます。 cputime のデフォルトの単位
は ‘seconds’ です。分を表す ‘m’, 時間を表す ‘h’, 分 + 秒を表す
‘mm:ss’ の形式などを用いることもできます。
resource も単位も、他と区別がつく範囲で後半部を省略可能です。
log (+) シェル変数 watch を表示し、そこにリストアップされているユーザが
ロ グ イ ン し て い ればログインした時刻に関わらず報告します。
watchlog についても参照してください。
login ログインシェルを終了して、/bin/login ( 訳 注: FreeBSD で は
/usr/bin/login です) のインスタンスで置き換えます。これはログオ
フする方法のひとつであり、sh(1) との互換性を保つ意味もありま す
。
logout ログインシェルを終了します。ignoreeof がセットされている場合に
特に役立つでしょう。
ls-F [-switch ...] [file ...] (+)
‘ls -F’ と同じようにファイルのリストを表示しますが、ずっと高 速
で す。各種の特別なファイル形式は特殊文字を用いて以下のように示
されます。
/ ディレクトリ
* 実行可能
# ブロック型デバイス
% キャラクタ型デバイス
| 名前付きパイプ (名前付きパイプのあるシステムでのみ)
= ソケット (ソケットのあるシステムでのみ)
@ シンボリックリンク (シンボリックリンクのあるシステムでのみ)
+ 隠 しディレクトリ (AIX のみ) またはコンテキスト依存 (HP/UX
のみ)
: ネットワーク特殊型 (HP/UX のみ)
シェル変数 listlinks がセットされている場合は、シンボリックリン
ク に関してより詳しく表示されます (もちろん、シンボリックリンク
を持つシステムでだけです)。
@ ディレクトリでないものへのシンボリックリンク
> ディレクトリへのシンボリックリンク
& どこへのリンクでもないシンボリックリンク
listlinks はシンボリックリンクの指し示すファイルが存在するパ ー
ティションのマウントを引き起こすため、ls-F を遅くしてしまいます
。
もしシェル変数 listfrags が ‘x’, ‘a’, ‘A’ のいずれかにセット さ
れているか、それらの組合せ (たとえば ‘xA’) にセットされている場
合は、これが ‘ls -xF’ や ‘ls -Fa’、もしくは組み合 わ せ て ‘ls
-FxA’ のように ls-F のフラグとして使われます。‘ls -C’ がデフォ
ルトでないマシンでは listflags が ‘x’ を含む場合には ls -xF’ の
よ う に、そうでなければ ls -F は ‘ls -CF’ のように振舞います。
ls -F は、何らかのスイッチが与えられた場合には ls(1) に引数を渡
すので、‘alias ls ls-F’ は通常、正しく動作します。
組 み込みの ls-F はファイルタイプや拡張子によってファイル名を色
分けすることができます。シェル変数 color tcsh と 環 境 変 数
LS_COLORS を参照してください。
migrate [-site] pid|%jobid ... (+)
migrate -site (+)
最 初の形式では指定したプロセスまたはジョブを、指定した場所もし
くはシステムパスによって決定されるデフォルトの場所に移動しま す
。
2 番目の形式は ‘migrate -site $$’ と同じ意味を持ちます。これは
現在のプロセスを指定した場所に移動します。シェルはその tty を失
わ ないことになっているので、シェル自身を移動することは予期しな
い動作の原因となります。(TCF のみ)
newgrp [-] group (+)
‘exec newgrp’ と同じ意味をもちます。newgrp(1) を参照してくだ さ
い 。シェルがこれを使うことができるようにコンパイルされている場
合にのみ使用可能です。シェル変数 version を参照してください。
nice [+number] [command]
シェルのスケジューリング優先度を number に設定するか 、 number
が指定されていない場合は 4 に設定します。command をつけると、コ
マンド command を適切な優先度で実行します。 number が大きいほど
、そのプロセスが獲得する CPU 時間は短くなります。スーパーユーザ
は ‘nice -number ...’ とすることにより負の値を設定することが で
き ます。コマンドは常にサブシェルから実行され、コマンドには単純
な if 文の場合と同じ制限が課されます。
nohup [command]
command をつけると、コマンド command をハングアップシグナルを無
視して実行するようにします。これらのコマンドが nohup をオーバー
ライドしてハングアップシグナルに対して自分自身で応答するよう に
す ることがあることに注意してください。引数のない場合 (シェルス
クリプト中でのみ許されます)、スクリプトのそれ以降の部分でシェル
は ハングアップシグナルを無視するようになります。シグナル処理と
、組み込みコマンド hup についても参照してください。
notify [%job ...]
ユーザに非同期的に指定したジョブ (%job が省略された場合はカレン
ト ジョブ) の状態に何らかの変化があった場合に非同期的に、通知す
るようにします。この場合は通常と異なり、次のプロンプトが出力 さ
れるまで待ちません。 job は Jobs に記述されているように番号、文
字列、‘’, ‘%’, ‘+’, ‘-’ のどれでも許されます。シェル変数 notify
も参照してください。
onintr [-|label]
割 り込み時のシェルの動作を制御します。引数がなければ、シェルの
デフォルトの割り込み時の動作に設定されます。この場合は、シェ ル
ス クリプトは割り込みで中断され、コマンド実行時はコマンドの実行
を中断してコマンド入力待ちに戻ります。 ‘-’ が指定された場合はす
べての割り込みが無視されます。 label を指定すると、割り込みが発
生したり子プロセスが割り込みで中断したりした場合に ‘goto label’
を実行します。
onintr は、システムのスタートアップファイル (FILES を参照) で割
り込みが禁止されている場合には無視されます。
popd [-p] [-l] [-n|-v] [+n]
引数がなければ、ディレクトリスタックからひとつ値を取り出して 、
そこに移動します。‘+n’ のように数値を与えると、ディレクトリスタ
ックの n’ 番目のエントリを破棄します。
また、すべての形式の popd は dirs のようにディレクトリスタッ ク
の最後のエントリを表示します。シェル変数 pushdsilent はこれを抑
制し、 -p フラグによって pushdsilent の動作をオーバーライドする
ことができます。 -l, -n, -v フラグは popd でも、dirs と同じ意味
をもちます。
printenv [name] (+)
すべての環境変数の名前と値を表示するか、name を与えた場合には環
境変数 name の値を表示します。
pushd [-p] [-l] [-n|-v] [name|+n]
引 数がなければ、ディレクトリスタックの一番上にあるふたつのエン
トリを入れ換えます。もし pushdtohome がセットされていれば、引数
な しの pushd は cd のように ‘pushd ~’ を行います。 (+) name を
つけると、現在の作業ディレクトリをディレクトリスタックに積ん で
name に移動します。もし name が ‘-’ であれば、ひとつ前の作業デ
ィレクトリとして解釈されます (ファイル名置 換 を 参 照) 。 (+)
dunique がセットされていれば、pushd は、スタックに name を積む
前にすべてのそれと同じものを指すエントリをスタックから除去し ま
す 。(+) ‘+n’ として番号をつけると、ディレクトリスタックの n 番
目のエントリがトップにくるようにスタックを回転します。 dextract
が セットされている場合、‘pushd +n’ を行うと n 番目のディレクト
リが展開されて、スタックのトップに移動されます。(+)
また、すべての形式の pushd は dirs と同じようにディレクトリスタ
ックの最終的な内容を表示します。シェル変数 pushdsilent をセット
することでこれをやめることができ、またさらにこれは -p フラグ に
よ ってオーバーライドすることが可能です。pushd に対する -l, -n,
-v フラグの意味は dirs のものと同様です。(+)
rehash path 変数の示すディレクトリの内容を保持する内部ハッシュテーブル
を再構成します。これはログインしている間に新しいコマンドが path
の示すディレクトリに追加された場合に必要です。これはあなたが 自
分 の個人的なディレクトリにコマンドを追加した場合か、システム管
理者がシステムディレクトリの内容を変更した場合にのみ行われる べ
き です。このコマンドはまた、チルダ記号を用いたホームディレクト
リ記述のキャッシュもフラッシュします。
repeat count command
指定されたコマンド command を count 回繰り返し実行します 。com-
mand に指定するものは一行 if 文で指定する command と同様の制限
を受けます。入出力リダイレクションは count が 0 であっても、 必
ず一回だけ処理されます。
rootnode //nodename (+)
ル ー ト ノ ー ド を //nodename に変更します。結果として ‘/’ は
‘//nodename’ として解釈されます。 (Domain/OS のみ)
sched (+)
sched [+]hh:mm command (+)
sched -n (+)
最初の形式は、予定されているイベントのリストを表示します。シ ェ
ル変数 sched は予定されているイベントのリストを表示する形式を設
定するためにセットされます。 3 番目の形式は command を予定さ れ
ているイベントのリストに追加します。たとえば、
> sched 11:00 echo It\’s eleven o\’clock.
は 、午前 11 時に ‘It’s eleven o’clock.’ を表示させます。時間は
12 時間制の AM/PM を指定する書式でも構いません。
> sched 5pm set prompt=’[%h] It\’s after 5; go home: >’
また、現在時刻からの相対的な時間でも構いません。
> sched +2:15 /usr/lib/uucp/uucico -r1 -sother
相対的な指定では AM/PM を使うべきではありません。 3 番目の書 式
では n 番のイベントをリストから削除します。
> sched
1 Wed Apr 4 15:42 /usr/lib/uucp/uucico -r1 -sother
2 Wed Apr 4 17:00 set prompt=[%h] It’s after 5; go
home: >
> sched -2
> sched
1 Wed Apr 4 15:42 /usr/lib/uucp/uucico -r1 -sother
予定イベントのリストにあるコマンドは、コマンドがリストに入れ ら
れ てから最初のプロンプトが出たあとで実行されます。実行の正確な
時間を過ぎてしまうことはありますが、次のプロンプトでは遅れた コ
マ ンドが実行されます。シェルがユーザのコマンド入力を待っている
間に実行予定時間が来たコマンドは直ちに実行されます。しかし、 既
に 実行されているコマンドの実行に割り込むことはできませんし、予
定されていたコマンドの実行についても同様です。
この仕組みはいくつかの Unix システムに実装されている at(1) に似
て いますが同じではありません。指定した時刻通りにコマンドが実行
できないことがあるのは非常に大きな短所です。しかしこの仕組み の
長 所は、sched はシェルから直接実行でき、シェル変数やその他の資
源へのアクセスができるということです。これは時刻によってユー ザ
の作業環境を変化させることを可能にします。
set
set name ...
set name=word ...
set [-r] [-f|-l] name=(wordlist) ... (+)
set name[index]=word ...
set -r (+)
set -r name ... (+)
set -r name=word ... (+)
1 番目の形式ではすべてのシェル変数の値を表示します。複数の単語
からなる値を持つ変数は括弧で囲まれた値のリストとして表示しま す
。 2 番目の形式では name に空文字列をセットします。 3 番目の形
式では name に単一の単語 word をセットします。 4 番目の形式では
name に wordlist で示した単語のリストをセットします。すべての場
合においてコマンド置換やファイル名置換が値に対して行わ れ ま す
。-r が指定された場合には、値は読み取り専用でセットされます。-f
または -l が指定された場合には、単語リストの中での順番を保ち な
が ら重複した単語が取り除かれます。 -f は最初に出てきたものをリ
ストに残し、-l は最後に出てきたものをリストに残します。 5 番 目
の書式では変数 name の index 番目の要素に word をセットします。
この場合この要素は既に存在していなければなりません。 6 番目の書
式 は読み取り専用にセットされているシェル変数の名前の一覧を表示
します。 7 番目の書式は name を、値の有無に関わらず読み取り専用
に セットします。 8 番目の書式は 3 番目の書式と同じですが、同時
に name を読み取り専用にセットします。
複数の変数をセットしたり、読み取り専用にセットするためにひと つ
の set コマンドへの引数を繰り返すことができます。しかし、変数へ
の代入処理を開始する前に変数展開処理が一度に行われることに注 意
してください。また、‘=’ は name と wordの両方と接しているか、空
白で区切られているかのどちらかであり、片方だけと接してはいけ な
いことに注意してください。組み込みコマンド unset についても参照
してください。
setenv [name [value]]
引数がなければ、すべての環境変数の名前と値を表示します 。 name
を 与 えられた場合は、環境変数 name の値を value にセットするか
、value がなければ空文字列にセットします。
setpath path (+)
setpath(1) と同様です。(Mach のみ)
setspath LOCAL|site|cpu ... (+)
システム実行パスを設定します。(TCF のみ)
settc cap value (+)
シェルに端末ケーパビリティ cap (termcap(5) で定義されたもの) は
値 value を持つことを教えます。妥当性のチェックは行われません。
Concept 端末のユーザは、一番右の桁で適切な折り返しを行うため に
‘settc xn no’ を行う必要があるかもしれません。
setty [-d|-q|-x] [-a] [[+|-]mode] (+)
シェルが変更してはならない tty モード (端末管理を参照) を制御し
ます。 -d, -q, -x は setty に、それぞれ ‘edit’, ‘quote’, ‘exe-
cute’ 時の tty モードをセットします。 -d, -q, -x が指定されない
場合、 ‘execute’ が使用されます。
他の引数がなければ、setty はオン (‘+mode’) またはオフ (‘-mode’)
に 固定されているモードを一覧表示します。使用可能なモードはシス
テムごとに異なるため、表示も異なります。 -a をつけると、固定 さ
れているかどうかにかかわらずすべての tty モードを一覧表示します
。 +mode, -mode, mode は、それぞれモード mode をオンに固定、 オ
フ に 固 定 、非固定にします。たとえば、‘setty +echok echoe’ は
‘echok’ をオンに固定し、シェルがコマンドを実行する際に ‘echoe’
モードをオンにしたりオフにしたりできるようにします。
setxvers [string] (+)
string に試験的なバージョンプリフィックスをセットし、 string が
省略された場合にはそれを削除します。(TCF のみ)
shift [variable]
引数がなければ、argv[1] を破棄してメンバを左にずらします。 argv
がセットされていなかったり、値が 1 つもなかった場合にはエラーに
なります。変数名 variable を指定すると、変数 variable に対し て
同じ動作を行います。
source [-h] name [args ...]
name からコマンドを読み取って実行します。コマンドはヒストリリス
トには残されません。もし引数 args が与えられればそれは argv に
入れられます。(+) source コマンドは入れ子にすることができます。
もし入れ子のレベルがあまりに深くなり過ぎると、シェルはファイ ル
記 述子の不足を起こすでしょう。 source でのエラーはすべての入れ
子になっている source の実行を停止します。 -h を付けると、コ マ
ン ドを実行するかわりに ‘history -L’ のようにヒストリリストに入
力されます。
stop %job|pid ...
指定したバックグラウンドで実行されているジョブまたはプロセス を
停 止します。job は番号か、文字列か、あるいはジョブに示されてい
る ‘’, ‘%’, ‘+’, ‘-’ のいずれかを指定します。デフォルト の job
は 存在しないので、ただ ‘stop’ を実行するだけではカレントジョブ
を停止することにはなりません。
suspend ^Z で送られるような stop シグナルが送られたかのように、その場で
シェルを停止させます。これは多くの場合 su(1) で起動したシェルを
停止するのに用いられます。
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw 指定された文字列 string に対して、各 case ラベルを連続的にマ ッ
チさせます。string にはそれに先だってコマンド置換とファイル名置
換が行われます。case ラベルには変数置換が行われ、ファイル名メタ
キ ャ ラ ク タ の ‘*’, ‘?’, ‘[...]’ を用いることができます。
‘default’ ラベルが出てくるまでにどの case ラベルともマッチし な
か っ た場合、default ラベルの後から実行が開始されます。各 case
ラベルと default ラベルは行の最初になければなりません。 breaksw
コ マ ンドは実行を中断して endsw の後から再開させます。 breaksw
を使用しない場合は C 言語と同様に case ラベルや default ラベ ル
を通過して実行が続けられます。もしマッチするラベルも default ラ
ベルも存在しない場合は、実行は endsw の後から再開されます。
telltc (+)
端末ケーパビリティのすべての値を一覧表示します (termcap(5) を参
照)。
time [command]
コ マンド command (エイリアスやパイプライン、コマンドリストや括
弧でくくったコマンドリストでない単純なものでなければなりません)
を 実行し、変数 time の項で説明する形式で、実行所用時間に関する
要約を表示します。必要ならば、コマンド終了時に時間を表示する た
め の追加のシェルが生成されます。command を指定しなかった場合は
、現在のシェルとその子プロセスが使用した時間に関する要約が表 示
されます。
umask [value]
8 進数で指定されたファイル作成マスクを value に設定します。一般
的なマスクの値としては、グループにすべての権限を与え、その他 に
は読み取りと実行のみを許可する 002 や、グループとその他に読み取
りと実行を許可する 022 があります。 value を省略すると、現在 の
ファイル作成マスクを表示します。
unalias pattern
パターン pattern にマッチするすべてのエイリアスを削除します。し
たがって ‘unalias *’ とすることですべてのエイリアスを削除できま
す。 unalias するものがなかった場合もエラーにはなりません。
uncomplete pattern (+)
パターン pattern にマッチするすべての補完対象を削除します。した
がって ‘uncomplete *’ とすることですべての補完対象を削除しま す
。 uncomplete するものがなかった場合もエラーにはなりません。
unhash 実行プログラムの検索を高速化する内部ハッシュテーブルの使用を禁
止します。
universe universe (+)
universe を universe に設定します。(Masscomp/RTU のみ)
unlimit [-h] [resource]
リソース resource の制限を解除します。resource が指定されない場
合 は、すべてのリソースに関する制限が解除されます。 -h が指定さ
れると、対応するハードリミットが解除されます。これはスーパー ユ
ーザのみが行うことができます。
unset pattern
パターン pattern にマッチするすべての変数を、読み取り専用の場合
も含めて削除します。したがって ‘unset *’ とすることによって読み
取 り専用のものも含めてすべての変数が削除されますが、これは良い
ことではありません。 unset するものがなかった場合もエラーにはな
りません。
unsetenv pattern
パターン pattern にマッチするすべての環境変数を削除します。した
がって ‘unsetenv *’ とすることによってすべての環境変数を削除 す
る ことができますが、これは良いことではありません。 unsetenv す
る環境変数がなかった場合もエラーにはなりません。
ver [systype [command]] (+)
引数が与えられなかった場合は SYSTYPE を表示します。 systype を
指定した場合は、SYSTYPE を systype に設定します。systype とコマ
ンド command を指定した場合は、systype で command を実行しま す
。systype は ‘bsd4.3’ か ‘sys5.3’ のいずれかです。 (Domain/OS
のみ)
wait すべてのバックグラウンドジョブの終了を待ちます。対話的にシェ ル
が 実行されている場合、割り込みにより wait を停止することができ
ます。この際シェルはまだ終了していないすべてのジョブの名前と そ
の番号を表示します。
warp universe (+)
universe を universe に設定します。(Convex/OS のみ)
watchlog (+)
組 み込みコマンド log の別名です (そちらも参照)。コンパイル時に
使用できるように設定されている場合にのみ使用可能です。シェル 変
数 version を参照してください。
where command (+)
コ マンド command について、エイリアスや組み込みコマンド、 path
にある実行可能ファイルを含めてシェルの知っているすべての実体 を
一覧表示します。
which command (+)
コ マンド command が、path の検索などの処理のあとで、実際に実行
されるコマンドを表示します。組み込みのものは which(1) とほと ん
ど 同じですが、 tcsh のエイリアスや組み込みコマンドついても正し
く報告し、また 10 から 100 倍高速です。編集コマンド which-com-
mand についても参照してください。
while (expr)
...
end 指定された式 expr (式で述べられている式) の評価結果が 0 でない
限り、while とそれに対応する end の間のコマンドを繰り返し実行し
ま す。 while と end はその行に単独で書かれなければなりません。
break と continue は、ループを途中で中断したり再開する場合に 使
用 します。入力が端末の場合は、foreach の場合と同じように、ルー
プの内容を一通り入力するまでユーザにプロンプトが出力されます。
特別なエイリアス (+)
これらのエイリアスは、設定されている場合それぞれ指示された時刻に自動 的
に実行されます。これらのエイリアスは、初期状態ではすべて未定義です。
beepcmd シェルが端末ベルを鳴らしたいときに実行されます。
cwdcmd 作業ディレクトリが変更されるたびに実行されます。たとえば、ユー
ザが X Window System 上で作業していて、 xterm(1) および twm(1)
の ように、タイトルバーをサポートしているリペアレントウインドウ
マネージャを使用していて、
> alias cwdcmd ’echo -n "^[]2;${HOST}:$cwd ^G"’
を実行すると、シェルは、動作中の xterm(1) のタイトルをホスト 名
、 コロン、そしてカレント作業ディレクトリのフルパスに変更します
。これをもっと面白く実行するには、次のようにします。
> alias cwdcmd ’echo -n
"^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"’
こ うすると、ホスト名および作業ディレクトリはタイトルバーに変更
されますが、アイコンマネージャのメニューにはホスト名しか表示 さ
れなくなります。
cwdcmd 中に cd, pushd あるいは popd を置くと、無限ループを引き
起こす可能性があることに注意してください。そういうことをする 人
は 、そうしてしまった代償は受けるものだというのが作者の見解です
。
jobcmd 各コマンドが実行される前またはコマンドが状態を変える前に実行 し
ます。 postcmd と似ていますが、組み込みコマンドでは表示しません
。
> alias jobcmd ’echo -n "^[]2\;\!#^G"’
として vi foo.c を実行すると、コマンド文字列が xterm タイトルバ
ーに表示されます。
helpcommand
run-help 編集コマンドが実行します。ヘルプが探すコマンド名は、単
一の引数として渡されます。たとえば、
> alias helpcommand ’\!:1 --help’
とすると、GNU のヘルプ呼び出し方法を使った、コマンドそのもの の
ヘ ルプ表示が実行されます。現在のところ、たくさんのコマンドを書
いたテーブルを使う以外には、いろいろな呼び出し方法 (た と え ば
、Unix の ‘-h’ オプション)を使い分ける簡単な方法はありません。
periodic
tperiod 分おきに実行されます。このエイリアスは、たとえば新し い
メ ールが届いたというような、日常的ではあってもそれほど頻繁には
起こらない変更点をチェックするのに便利な手段を提供します。た と
えば、
> set tperiod = 30
> alias periodic checknews
と す る と 、30 分おきに checknews(1) プログラムが起動します。
periodic が設定されているが、tperiod が設定されていないかあるい
は 0 に設定されている場合、periodic は precmd のように振る舞い
ます。
precmd プロンプトが表示される直前に実行されます。たとえば、
> alias precmd date
とすると、各コマンド用にシェルプロンプトが表示さ れ る 直 前 に
date(1) が起動します。 precmd に何を設定できるかには制限はあり
ませんが、慎重に選んでください。
postcmd 各コマンドが実行される前に実行されます。
> alias postcmd ’echo -n "^[]2\;\!#^G"’
とすると、vi foo.c を実行すると xterm のタイトルバーにこのコ マ
ンド文字列が書かれます。
shell スクリプト中でインタプリタを指定していない実行可能スクリプト用
のインタプリタを指定します。最初の単語は、使用したいインタプ リ
タ へ の フ ルパスでなくてはなりません (たとえば、‘/bin/csh’ や
‘/usr/local/bin/tcsh’)。
特別なシェル変数
このセクションで述べる変数は、シェルにとっては特別な意味のあるもので す
。
シ ェ ル は、起動時に次の変数を設定します。addsuffix, argv, autologout,
command, echo_style, edit, gid, group, home, loginsh, oid, path,
prompt, prompt2, prompt3, shell, shlvl, tcsh, term, tty, uid, user そし
て version です。これらの変数は、起動後はユーザが変更しない限り変更され
ません。シェルは、必要があれば、cwd, dirstack, owd および status を更新
し、ログアウト時に logout を設定します。
シェルは、シェル変数 afsuser, group, home, path, shlvl, term お よ び
user と同名の環境変数との同期を取ります。つまり、環境変数が変更されると
、シェルは対応するシェル変数を合致するように変更するのです (シェル変 数
が 読 み込み専用でない場合です)。また、その逆も行います。ここで、cwd と
PWD は同じ意味を持ちますが、この方法では同期は行われないということに 注
意 してください。また、シェルは、自動的に path と PATH の違った形式を相
互変換するということにも注意してください。
addsuffix (+)
これが設定されている場合、ファイル名が補完の際に完全に一致す る
ときに、一致したものがディレクトリの場合には末尾に ‘/’ を付け加
え、通常のファイルの場合には末尾にスペースを加えます。デフォ ル
トで設定されています。
afsuser (+)
これが設定されている場合、autologout の autolock 機能は、ローカ
ルのユーザ名の代わりにこの値を kerberos 認証用に使います。
ampm (+)
これが設定されている場合、時刻が 12 時間単位の AM/PM フォーマッ
トですべて表示されます。
argv シェルへの引数です。位置パラメータは argv から取られます。すな
わち、‘$1’ は ‘$argv[1]’ に置き換えられるといった具合です。デフ
ォルトで設定されていますが、通常対話型シェルでは空です。
autocorrect (+)
これが設定されている場合は、補完を試みる前に自動的に spell-word
編集コマンドが実行されます。
autoexpand (+)
これが設定されている場合は、補完を試みる前に自動 的 に expand-
history 編集コマンドが実行されます。
autolist (+)
こ れが設定されている場合は、あいまいな補完を行った後、可能性の
あるものをリストします。
‘ambiguous’ が設定されている場合、可能性のあるものをリストする
のは、補完によって何の文字も追加されなかった場合に限られます。
autologout (+)
1 番目の単語は、時間を分単位で表しており、この時間以上の間、何
の処理もしていなければ自動的にログアウトされます。2 番目の単 語
は オプションであり、ここで指定された時間以上の間、何の処理もし
ていなければ自動ロックがかかります。シェルが自動的にログアウ ト
す る 際 に は 、シェルは ‘auto-logout’ と出力し、logout 変数を
‘automatic’ に設定し、そして終了します。シェルが自動的にロッ ク
さ れたユーザは、作業を続けたいなら自分のパスワードを入力するこ
とが必要になります。5 回入力に失敗すると、自動的にログアウト し
ま す。ログインシェルおよびスーパユーザのシェルでは、デフォルト
で ‘60’(60 分後自動的にログアウトし、ロックはかけない) に設定さ
れ ています。しかし、シェルがウインドウシステムのもとで動いてい
ると認識した場合 (すなわち、DISPLAY 環境変数が設定されて い る)
や、 tty が疑似 tty(pty) である場合、あるいは、シェルがそのよう
にはコンパイルされていない場合 (version シェル変数を参照) に は
設定されません。 afsuser および logout シェル変数も参照してくだ
さい。
backslash_quote (+)
これが設定されている場合、バックスラッシュ (‘\’) は 常 に ‘\’,
‘’’, および ‘"’ でクォートされます。これによって、複雑なクォー
トをする手間が緩和されますが、 csh(1) スクリプト中で文法エラ ー
をひき起こす可能性が出てきます。
catalog メッセージカタログのファイル名です。これが設定されている場合、
デフォルトの ‘tcsh’ の代りに ‘tcsh.${catalog}’ を、メッセージカ
タログとして tcsh は使用します。
cdpath カレントディレクトリ中にサブディレクトリが見つからなかった場合
に、 cd が探索すべきディレクトリのリストです。
color これが設定されている場合、組み込みコマンド ls-F 用のカラー表 示
を 有効にし、--color=auto を ls に渡します。あるいは、ただ 1 つ
のコマンドに対してカラー表示を有効にするため、ls-F または ls の
みに設定することができます。何に対しても設定しない場合は、(ls-F
ls) に対して設定したのと等価です。
colorcat
これが設定されている場合は、NLS メッセージファイルに対してカ ラ
ー 用エスケープシーケンスを有効にします。これによって、色のつい
た NLS メッセージが表示されます。
command (+)
これが設定されている場合、シェルに渡されたコマンドは、 -c フ ラ
グ (そちらも参照) をつけたものになります。
complete (+)
これが ‘enhance’ に設定されている場合、補完は、 1) 大文字小文字
を無視し、2) ピリオド、ハイフン、およびアンダスコア (‘.’, ‘-’,
‘_’) を単語の区切り文字とみなし、ハイフンとアンダスコアを等価な
ものとみなします。
continue (+)
コマンドリストに対してこれが設定されている場合、シェルはリス ト
されているコマンドを継続実行し、新たにコマンドを開始しません。
continue_args (+)
continue と同じですが、シェルは次のコマンドを実行します:
echo ‘pwd‘ $argv > ~/.
TCSH(1) TCSH(1)
NAME
tcsh - C shell with file name completion and command line editing
SYNOPSIS
tcsh [-bcdefFimnqstvVxX] [-Dname[=value]] [arg ...]
tcsh -l
DESCRIPTION
tcsh is an enhanced but completely compatible version of the Berkeley
UNIX C shell, csh(1). It is a command language interpreter usable both
as an interactive login shell and a shell script command processor. It
includes a command-line editor (see The command-line editor), pro-
grammable word completion (see Completion and listing), spelling cor-
rection (see Spelling correction), a history mechanism (see History
substitution), job control (see Jobs) and a C-like syntax. The NEW
FEATURES section describes major enhancements of tcsh over csh(1).
Throughout this manual, features of tcsh not found in most csh(1)
implementations (specifically, the 4.4BSD csh) are labeled with ‘(+)’,
and features which are present in csh(1) but not usually documented are
labeled with ‘(u)’.
Argument list processing
If the first argument (argument 0) to the shell is ‘-’ then it is a
login shell. A login shell can be also specified by invoking the shell
with the -l flag as the only argument.
The rest of the flag arguments are interpreted as follows:
-b Forces a ‘‘break’’ from option processing, causing any further
shell arguments to be treated as non-option arguments. The remain-
ing arguments will not be interpreted as shell options. This may
be used to pass options to a shell script without confusion or pos-
sible subterfuge. The shell will not run a set-user ID script
without this option.
-c Commands are read from the following argument (which must be
present, and must be a single argument), stored in the command
shell variable for reference, and executed. Any remaining argu-
ments are placed in the argv shell variable.
-d The shell loads the directory stack from ~/.cshdirs as described
under Startup and shutdown, whether or not it is a login shell. (+)
-Dname[=value]
Sets the environment variable name to value. (Domain/OS only) (+)
-e The shell exits if any invoked command terminates abnormally or
yields a non-zero exit status.
-f The shell does not load any resource or startup files, or perform
any command hashing, and thus starts faster.
-F The shell uses fork(2) instead of vfork(2) to spawn processes. (+)
-i The shell is interactive and prompts for its top-level input, even
if it appears to not be a terminal. Shells are interactive without
this option if their inputs and outputs are terminals.
-l The shell is a login shell. Applicable only if -l is the only flag
specified.
-m The shell loads ~/.tcshrc even if it does not belong to the effec-
tive user. Newer versions of su(1) can pass -m to the shell. (+)
-n The shell parses commands but does not execute them. This aids in
debugging shell scripts.
-q The shell accepts SIGQUIT (see Signal handling) and behaves when it
is used under a debugger. Job control is disabled. (u)
-s Command input is taken from the standard input.
-t The shell reads and executes a single line of input. A ‘\’ may be
used to escape the newline at the end of this line and continue
onto another line.
-v Sets the verbose shell variable, so that command input is echoed
after history substitution.
-x Sets the echo shell variable, so that commands are echoed immedi-
ately before execution.
-V Sets the verbose shell variable even before executing ~/.tcshrc.
-X Is to -x as -V is to -v.
--help
Print a help message on the standard output and exit. (+)
--version
Print the version/platform/compilation options on the standard out-
put and exit. This information is also contained in the version
shell variable. (+)
After processing of flag arguments, if arguments remain but none of the
-c, -i, -s, or -t options were given, the first argument is taken as
the name of a file of commands, or ‘‘script’’, to be executed. The
shell opens this file and saves its name for possible resubstitution by
‘$0’. Because many systems use either the standard version 6 or ver-
sion 7 shells whose shell scripts are not compatible with this shell,
the shell uses such a ‘standard’ shell to execute a script whose first
character is not a ‘#’, i.e., that does not start with a comment.
Remaining arguments are placed in the argv shell variable.
Startup and shutdown
A login shell begins by executing commands from the system files
/etc/csh.cshrc and /etc/csh.login. It then executes commands from
files in the user’s home directory: first ~/.tcshrc (+) or, if
~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of the
histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the
value of the dirsfile shell variable) (+). The shell may read
/etc/csh.login before instead of after /etc/csh.cshrc, and ~/.login
before instead of after ~/.tcshrc or ~/.cshrc and ~/.history, if so
compiled; see the version shell variable. (+)
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on
startup.
For examples of startup files, please consult http://tcshrc.source-
forge.net.
Commands like stty(1) and tset(1), which need be run only once per
login, usually go in one’s ~/.login file. Users who need to use the
same set of files with both csh(1) and tcsh can have only a ~/.cshrc
which checks for the existence of the tcsh shell variable (q.v.) before
using tcsh-specific commands, or can have both a ~/.cshrc and a
~/.tcshrc which sources (see the builtin command) ~/.cshrc. The rest
of this manual uses ‘~/.tcshrc’ to mean ‘~/.tcshrc or, if ~/.tcshrc is
not found, ~/.cshrc’.
In the normal case, the shell begins reading commands from the termi-
nal, prompting with ‘> ’. (Processing of arguments and the use of the
shell to process files containing command scripts are described later.)
The shell repeatedly reads a line of command input, breaks it into
words, places it on the command history list, parses it and executes
each command in the line.
One can log out by typing ‘^D’ on an empty line, ‘logout’ or ‘login’ or
via the shell’s autologout mechanism (see the autologout shell vari-
able). When a login shell terminates it sets the logout shell variable
to ‘normal’ or ‘automatic’ as appropriate, then executes commands from
the files /etc/csh.logout and ~/.logout. The shell may drop DTR on
logout if so compiled; see the version shell variable.
The names of the system login and logout files vary from system to sys-
tem for compatibility with different csh(1) variants; see FILES.
Editing
We first describe The command-line editor. The Completion and listing
and Spelling correction sections describe two sets of functionality
that are implemented as editor commands but which deserve their own
treatment. Finally, Editor commands lists and describes the editor
commands specific to the shell and their default bindings.
The command-line editor (+)
Command-line input can be edited using key sequences much like those
used in GNU Emacs or vi(1). The editor is active only when the edit
shell variable is set, which it is by default in interactive shells.
The bindkey builtin can display and change key bindings. Emacs-style
key bindings are used by default (unless the shell was compiled other-
wise; see the version shell variable), but bindkey can change the key
bindings to vi-style bindings en masse.
The shell always binds the arrow keys (as defined in the TERMCAP envi-
ronment variable) to
down down-history
up up-history
left backward-char
right forward-char
unless doing so would alter another single-character binding. One can
set the arrow key escape sequences to the empty string with settc to
prevent these bindings. The ANSI/VT100 sequences for arrow keys are
always bound.
Other key bindings are, for the most part, what Emacs and vi(1) users
would expect and can easily be displayed by bindkey, so there is no
need to list them here. Likewise, bindkey can list the editor commands
with a short description of each.
Note that editor commands do not have the same notion of a ‘‘word’’ as
does the shell. The editor delimits words with any non-alphanumeric
characters not in the shell variable wordchars, while the shell recog-
nizes only whitespace and some of the characters with special meanings
to it, listed under Lexical structure.
Completion and listing (+)
The shell is often able to complete words when given a unique abbrevia-
tion. Type part of a word (for example ‘ls /usr/lost’) and hit the tab
key to run the complete-word editor command. The shell completes the
filename ‘/usr/lost’ to ‘/usr/lost+found/’, replacing the incomplete
word with the complete word in the input buffer. (Note the terminal
‘/’; completion adds a ‘/’ to the end of completed directories and a
space to the end of other completed words, to speed typing and provide
a visual indicator of successful completion. The addsuffix shell
variable can be unset to prevent this.) If no match is found (perhaps
‘/usr/lost+found’ doesn’t exist), the terminal bell rings. If the word
is already complete (perhaps there is a ‘/usr/lost’ on your system, or
perhaps you were thinking too far ahead and typed the whole thing) a
‘/’ or space is added to the end if it isn’t already there.
Completion works anywhere in the line, not at just the end; completed
text pushes the rest of the line to the right. Completion in the mid-
dle of a word often results in leftover characters to the right of the
cursor that need to be deleted.
Commands and variables can be completed in much the same way. For
example, typing ‘em[tab]’ would complete ‘em’ to ‘emacs’ if emacs were
the only command on your system beginning with ‘em’. Completion can
find a command in any directory in path or if given a full pathname.
Typing ‘echo $ar[tab]’ would complete ‘$ar’ to ‘$argv’ if no other
variable began with ‘ar’.
The shell parses the input buffer to determine whether the word you
want to complete should be completed as a filename, command or vari-
able. The first word in the buffer and the first word following ‘;’,
‘|’, ‘|&’, ‘&&’ or ‘||’ is considered to be a command. A word begin-
ning with ‘$’ is considered to be a variable. Anything else is a file-
name. An empty line is ‘completed’ as a filename.
You can list the possible completions of a word at any time by typing
‘^D’ to run the delete-char-or-list-or-eof editor command. The shell
lists the possible completions using the ls-F builtin (q.v.) and
reprints the prompt and unfinished command line, for example:
> ls /usr/l[^D]
lbin/ lib/ local/ lost+found/
> ls /usr/l
If the autolist shell variable is set, the shell lists the remaining
choices (if any) whenever completion fails:
> set autolist
> nm /usr/lib/libt[tab]
libtermcap.a@ libtermlib.a@
> nm /usr/lib/libterm
If autolist is set to ‘ambiguous’, choices are listed only when comple-
tion fails and adds no new characters to the word being completed.
A filename to be completed can contain variables, your own or others’
home directories abbreviated with ‘~’ (see Filename substitution) and
directory stack entries abbreviated with ‘=’ (see Directory stack sub-
stitution). For example,
> ls ~k[^D]
kahn kas kellogg
> ls ~ke[tab]
> ls ~kellogg/
or
> set local = /usr/local
> ls $lo[tab]
> ls $local/[^D]
bin/ etc/ lib/ man/ src/
> ls $local/
Note that variables can also be expanded explicitly with the expand-
variables editor command.
delete-char-or-list-or-eof lists at only the end of the line; in the
middle of a line it deletes the character under the cursor and on an
empty line it logs one out or, if ignoreeof is set, does nothing.
‘M-^D’, bound to the editor command list-choices, lists completion pos-
sibilities anywhere on a line, and list-choices (or any one of the
related editor commands that do or don’t delete, list and/or log out,
listed under delete-char-or-list-or-eof) can be bound to ‘^D’ with the
bindkey builtin command if so desired.
The complete-word-fwd and complete-word-back editor commands (not bound
to any keys by default) can be used to cycle up and down through the
list of possible completions, replacing the current word with the next
or previous word in the list.
The shell variable fignore can be set to a list of suffixes to be
ignored by completion. Consider the following:
> ls
Makefile condiments.h~ main.o side.c
README main.c meal side.o
condiments.h main.c~
> set fignore = (.o \~)
> emacs ma[^D]
main.c main.c~ main.o
> emacs ma[tab]
> emacs main.c
‘main.c~’ and ‘main.o’ are ignored by completion (but not listing),
because they end in suffixes in fignore. Note that a ‘\’ was needed in
front of ‘~’ to prevent it from being expanded to home as described
under Filename substitution. fignore is ignored if only one completion
is possible.
If the complete shell variable is set to ‘enhance’, completion 1)
ignores case and 2) considers periods, hyphens and underscores (‘.’,
‘-’ and ‘_’) to be word separators and hyphens and underscores to be
equivalent. If you had the following files
comp.lang.c comp.lang.perl comp.std.c++
comp.lang.c++ comp.std.c
and typed ‘mail -f c.l.c[tab]’, it would be completed to ‘mail -f
comp.lang.c’, and ^D would list ‘comp.lang.c’ and ‘comp.lang.c++’.
‘mail -f c..c++[^D]’ would list ‘comp.lang.c++’ and ‘comp.std.c++’.
Typing ‘rm a--file[^D]’ in the following directory
A_silly_file a-hyphenated-file another_silly_file
would list all three files, because case is ignored and hyphens and
underscores are equivalent. Periods, however, are not equivalent to
hyphens or underscores.
Completion and listing are affected by several other shell variables:
recexact can be set to complete on the shortest possible unique match,
even if more typing might result in a longer match:
> ls
fodder foo food foonly
> set recexact
> rm fo[tab]
just beeps, because ‘fo’ could expand to ‘fod’ or ‘foo’, but if we type
another ‘o’,
> rm foo[tab]
> rm foo
the completion completes on ‘foo’, even though ‘food’ and ‘foonly’ also
match. autoexpand can be set to run the expand-history editor command
before each completion attempt, autocorrect can be set to spelling-cor-
rect the word to be completed (see Spelling correction) before each
completion attempt and correct can be set to complete commands automat-
ically after one hits ‘return’. matchbeep can be set to make comple-
tion beep or not beep in a variety of situations, and nobeep can be set
to never beep at all. nostat can be set to a list of directories
and/or patterns that match directories to prevent the completion mecha-
nism from stat(2)ing those directories. listmax and listmaxrows can be
set to limit the number of items and rows (respectively) that are
listed without asking first. recognize_only_executables can be set to
make the shell list only executables when listing commands, but it is
quite slow.
Finally, the complete builtin command can be used to tell the shell how
to complete words other than filenames, commands and variables. Com-
pletion and listing do not work on glob-patterns (see Filename substi-
tution), but the list-glob and expand-glob editor commands perform
equivalent functions for glob-patterns.
Spelling correction (+)
The shell can sometimes correct the spelling of filenames, commands and
variable names as well as completing and listing them.
Individual words can be spelling-corrected with the spell-word editor
command (usually bound to M-s and M-S) and the entire input buffer with
spell-line (usually bound to M-$). The correct shell variable can be
set to ‘cmd’ to correct the command name or ‘all’ to correct the entire
line each time return is typed, and autocorrect can be set to correct
the word to be completed before each completion attempt.
When spelling correction is invoked in any of these ways and the shell
thinks that any part of the command line is misspelled, it prompts with
the corrected line:
> set correct = cmd
> lz /usr/bin
CORRECT>ls /usr/bin (y|n|e|a)?
One can answer ‘y’ or space to execute the corrected line, ‘e’ to leave
the uncorrected command in the input buffer, ‘a’ to abort the command
as if ‘^C’ had been hit, and anything else to execute the original line
unchanged.
Spelling correction recognizes user-defined completions (see the com-
plete builtin command). If an input word in a position for which a
completion is defined resembles a word in the completion list, spelling
correction registers a misspelling and suggests the latter word as a
correction. However, if the input word does not match any of the pos-
sible completions for that position, spelling correction does not reg-
ister a misspelling.
Like completion, spelling correction works anywhere in the line, push-
ing the rest of the line to the right and possibly leaving extra char-
acters to the right of the cursor.
Beware: spelling correction is not guaranteed to work the way one
intends, and is provided mostly as an experimental feature. Sugges-
tions and improvements are welcome.
Editor commands (+)
‘bindkey’ lists key bindings and ‘bindkey -l’ lists and briefly
describes editor commands. Only new or especially interesting editor
commands are described here. See emacs(1) and vi(1) for descriptions
of each editor’s key bindings.
The character or characters to which each command is bound by default
is given in parentheses. ‘^character’ means a control character and
‘M-character’ a meta character, typed as escape-character on terminals
without a meta key. Case counts, but commands that are bound to let-
ters by default are bound to both lower- and uppercase letters for con-
venience.
complete-word (tab)
Completes a word as described under Completion and listing.
complete-word-back (not bound)
Like complete-word-fwd, but steps up from the end of the list.
complete-word-fwd (not bound)
Replaces the current word with the first word in the list of
possible completions. May be repeated to step down through the
list. At the end of the list, beeps and reverts to the incom-
plete word.
complete-word-raw (^X-tab)
Like complete-word, but ignores user-defined completions.
copy-prev-word (M-^_)
Copies the previous word in the current line into the input
buffer. See also insert-last-word.
dabbrev-expand (M-/)
Expands the current word to the most recent preceding one for
which the current is a leading substring, wrapping around the
history list (once) if necessary. Repeating dabbrev-expand
without any intervening typing changes to the next previous
word etc., skipping identical matches much like history-search-
backward does.
delete-char (not bound)
Deletes the character under the cursor. See also delete-char-
or-list-or-eof.
delete-char-or-eof (not bound)
Does delete-char if there is a character under the cursor or
end-of-file on an empty line. See also delete-char-or-list-or-
eof.
delete-char-or-list (not bound)
Does delete-char if there is a character under the cursor or
list-choices at the end of the line. See also delete-char-or-
list-or-eof.
delete-char-or-list-or-eof (^D)
Does delete-char if there is a character under the cursor,
list-choices at the end of the line or end-of-file on an empty
line. See also those three commands, each of which does only a
single action, and delete-char-or-eof, delete-char-or-list and
list-or-eof, each of which does a different two out of the
three.
down-history (down-arrow, ^N)
Like up-history, but steps down, stopping at the original input
line.
end-of-file (not bound)
Signals an end of file, causing the shell to exit unless the
ignoreeof shell variable (q.v.) is set to prevent this. See
also delete-char-or-list-or-eof.
expand-history (M-space)
Expands history substitutions in the current word. See History
substitution. See also magic-space, toggle-literal-history and
the autoexpand shell variable.
expand-glob (^X-*)
Expands the glob-pattern to the left of the cursor. See File-
name substitution.
expand-line (not bound)
Like expand-history, but expands history substitutions in each
word in the input buffer,
expand-variables (^X-$)
Expands the variable to the left of the cursor. See Variable
substitution.
history-search-backward (M-p, M-P)
Searches backwards through the history list for a command
beginning with the current contents of the input buffer up to
the cursor and copies it into the input buffer. The search
string may be a glob-pattern (see Filename substitution) con-
taining ‘*’, ‘?’, ‘[]’ or ‘{}’. up-history and down-history
will proceed from the appropriate point in the history list.
Emacs mode only. See also history-search-forward and i-search-
back.
history-search-forward (M-n, M-N)
Like history-search-backward, but searches forward.
i-search-back (not bound)
Searches backward like history-search-backward, copies the
first match into the input buffer with the cursor positioned at
the end of the pattern, and prompts with ‘bck: ’ and the first
match. Additional characters may be typed to extend the
search, i-search-back may be typed to continue searching with
the same pattern, wrapping around the history list if neces-
sary, (i-search-back must be bound to a single character for
this to work) or one of the following special characters may be
typed:
^W Appends the rest of the word under the cursor to
the search pattern.
delete (or any character bound to backward-delete-char)
Undoes the effect of the last character typed and
deletes a character from the search pattern if
appropriate.
^G If the previous search was successful, aborts the
entire search. If not, goes back to the last suc-
cessful search.
escape Ends the search, leaving the current line in the
input buffer.
Any other character not bound to self-insert-command terminates
the search, leaving the current line in the input buffer, and
is then interpreted as normal input. In particular, a carriage
return causes the current line to be executed. Emacs mode
only. See also i-search-fwd and history-search-backward.
i-search-fwd (not bound)
Like i-search-back, but searches forward.
insert-last-word (M-_)
Inserts the last word of the previous input line (‘!$’) into
the input buffer. See also copy-prev-word.
list-choices (M-^D)
Lists completion possibilities as described under Completion
and listing. See also delete-char-or-list-or-eof and list-
choices-raw.
list-choices-raw (^X-^D)
Like list-choices, but ignores user-defined completions.
list-glob (^X-g, ^X-G)
Lists (via the ls-F builtin) matches to the glob-pattern (see
Filename substitution) to the left of the cursor.
list-or-eof (not bound)
Does list-choices or end-of-file on an empty line. See also
delete-char-or-list-or-eof.
magic-space (not bound)
Expands history substitutions in the current line, like expand-
history, and inserts a space. magic-space is designed to be
bound to the space bar, but is not bound by default.
normalize-command (^X-?)
Searches for the current word in PATH and, if it is found,
replaces it with the full path to the executable. Special
characters are quoted. Aliases are expanded and quoted but
commands within aliases are not. This command is useful with
commands that take commands as arguments, e.g., ‘dbx’ and ‘sh
-x’.
normalize-path (^X-n, ^X-N)
Expands the current word as described under the ‘expand’ set-
ting of the symlinks shell variable.
overwrite-mode (unbound)
Toggles between input and overwrite modes.
run-fg-editor (M-^Z)
Saves the current input line and looks for a stopped job with a
name equal to the last component of the file name part of the
EDITOR or VISUAL environment variables, or, if neither is set,
‘ed’ or ‘vi’. If such a job is found, it is restarted as if
‘fg %job’ had been typed. This is used to toggle back and
forth between an editor and the shell easily. Some people bind
this command to ‘^Z’ so they can do this even more easily.
run-help (M-h, M-H)
Searches for documentation on the current command, using the
same notion of ‘current command’ as the completion routines,
and prints it. There is no way to use a pager; run-help is
designed for short help files. If the special alias helpcom-
mand is defined, it is run with the command name as a sole
argument. Else, documentation should be in a file named com-
mand.help, command.1, command.6, command.8 or command, which
should be in one of the directories listed in the HPATH envi-
ronment variable. If there is more than one help file only the
first is printed.
self-insert-command (text characters)
In insert mode (the default), inserts the typed character into
the input line after the character under the cursor. In over-
write mode, replaces the character under the cursor with the
typed character. The input mode is normally preserved between
lines, but the inputmode shell variable can be set to ‘insert’
or ‘overwrite’ to put the editor in that mode at the beginning
of each line. See also overwrite-mode.
sequence-lead-in (arrow prefix, meta prefix, ^X)
Indicates that the following characters are part of a multi-key
sequence. Binding a command to a multi-key sequence really
creates two bindings: the first character to sequence-lead-in
and the whole sequence to the command. All sequences beginning
with a character bound to sequence-lead-in are effectively
bound to undefined-key unless bound to another command.
spell-line (M-$)
Attempts to correct the spelling of each word in the input
buffer, like spell-word, but ignores words whose first charac-
ter is one of ‘-’, ‘!’, ‘^’ or ‘%’, or which contain ‘\’, ‘*’
or ‘?’, to avoid problems with switches, substitutions and the
like. See Spelling correction.
spell-word (M-s, M-S)
Attempts to correct the spelling of the current word as
described under Spelling correction. Checks each component of
a word which appears to be a pathname.
toggle-literal-history (M-r, M-R)
Expands or ‘unexpands’ history substitutions in the input
buffer. See also expand-history and the autoexpand shell vari-
able.
undefined-key (any unbound key)
Beeps.
up-history (up-arrow, ^P)
Copies the previous entry in the history list into the input
buffer. If histlit is set, uses the literal form of the entry.
May be repeated to step up through the history list, stopping
at the top.
vi-search-back (?)
Prompts with ‘?’ for a search string (which may be a glob-pat-
tern, as with history-search-backward), searches for it and
copies it into the input buffer. The bell rings if no match is
found. Hitting return ends the search and leaves the last
match in the input buffer. Hitting escape ends the search and
executes the match. vi mode only.
vi-search-fwd (/)
Like vi-search-back, but searches forward.
which-command (M-?)
Does a which (see the description of the builtin command) on
the first word of the input buffer.
yank-pop (M-y)
When executed immediately after a yank or another yank-pop,
replaces the yanked string with the next previous string from
the killring. This also has the effect of rotating the kill-
ring, such that this string will be considered the most
recently killed by a later yank command. Repeating yank-pop
will cycle through the killring any number of times.
Lexical structure
The shell splits input lines into words at blanks and tabs. The spe-
cial characters ‘&’, ‘|’, ‘;’, ‘<’, ‘>’, ‘(’, and ‘)’ and the doubled
characters ‘&&’, ‘||’, ‘<<’ and ‘>>’ are always separate words, whether
or not they are surrounded by whitespace.
When the shell’s input is not a terminal, the character ‘#’ is taken to
begin a comment. Each ‘#’ and the rest of the input line on which it
appears is discarded before further parsing.
A special character (including a blank or tab) may be prevented from
having its special meaning, and possibly made part of another word, by
preceding it with a backslash (‘\’) or enclosing it in single (‘’’),
double (‘"’) or backward (‘‘’) quotes. When not otherwise quoted a
newline preceded by a ‘\’ is equivalent to a blank, but inside quotes
this sequence results in a newline.
Furthermore, all Substitutions (see below) except History substitution
can be prevented by enclosing the strings (or parts of strings) in
which they appear with single quotes or by quoting the crucial charac-
ter(s) (e.g., ‘$’ or ‘‘’ for Variable substitution or Command substitu-
tion respectively) with ‘\’. (Alias substitution is no exception:
quoting in any way any character of a word for which an alias has been
defined prevents substitution of the alias. The usual way of quoting
an alias is to precede it with a backslash.) History substitution is
prevented by backslashes but not by single quotes. Strings quoted with
double or backward quotes undergo Variable substitution and Command
substitution, but other substitutions are prevented.
Text inside single or double quotes becomes a single word (or part of
one). Metacharacters in these strings, including blanks and tabs, do
not form separate words. Only in one special case (see Command substi-
tution below) can a double-quoted string yield parts of more than one
word; single-quoted strings never do. Backward quotes are special:
they signal Command substitution (q.v.), which may result in more than
one word.
Quoting complex strings, particularly strings which themselves contain
quoting characters, can be confusing. Remember that quotes need not be
used as they are in human writing! It may be easier to quote not an
entire string, but only those parts of the string which need quoting,
using different types of quoting to do so if appropriate.
The backslash_quote shell variable (q.v.) can be set to make back-
slashes always quote ‘\’, ‘’’, and ‘"’. (+) This may make complex
quoting tasks easier, but it can cause syntax errors in csh(1) scripts.
Substitutions
We now describe the various transformations the shell performs on the
input in the order in which they occur. We note in passing the data
structures involved and the commands and variables which affect them.
Remember that substitutions can be prevented by quoting as described
under Lexical structure.
History substitution
Each command, or ‘‘event’’, input from the terminal is saved in the
history list. The previous command is always saved, and the history
shell variable can be set to a number to save that many commands. The
histdup shell variable can be set to not save duplicate events or con-
secutive duplicate events.
Saved commands are numbered sequentially from 1 and stamped with the
time. It is not usually necessary to use event numbers, but the cur-
rent event number can be made part of the prompt by placing an ‘!’ in
the prompt shell variable.
The shell actually saves history in expanded and literal (unexpanded)
forms. If the histlit shell variable is set, commands that display and
store history use the literal form.
The history builtin command can print, store in a file, restore and
clear the history list at any time, and the savehist and histfile shell
variables can be can be set to store the history list automatically on
logout and restore it on login.
History substitutions introduce words from the history list into the
input stream, making it easy to repeat commands, repeat arguments of a
previous command in the current command, or fix spelling mistakes in
the previous command with little typing and a high degree of confi-
dence.
History substitutions begin with the character ‘!’. They may begin
anywhere in the input stream, but they do not nest. The ‘!’ may be
preceded by a ‘\’ to prevent its special meaning; for convenience, a
‘!’ is passed unchanged when it is followed by a blank, tab, newline,
‘=’ or ‘(’. History substitutions also occur when an input line begins
with ‘^’. This special abbreviation will be described later. The
characters used to signal history substitution (‘!’ and ‘^’) can be
changed by setting the histchars shell variable. Any input line which
contains a history substitution is printed before it is executed.
A history substitution may have an ‘‘event specification’’, which indi-
cates the event from which words are to be taken, a ‘‘word designa-
tor’’, which selects particular words from the chosen event, and/or a
‘‘modifier’’, which manipulates the selected words.
An event specification can be
n A number, referring to a particular event
-n An offset, referring to the event n before the current
event
# The current event. This should be used carefully in
csh(1), where there is no check for recursion. tcsh allows
10 levels of recursion. (+)
! The previous event (equivalent to ‘-1’)
s The most recent event whose first word begins with the
string s
?s? The most recent event which contains the string s. The
second ‘?’ can be omitted if it is immediately followed by
a newline.
For example, consider this bit of someone’s history list:
9 8:30 nroff -man wumpus.man
10 8:31 cp wumpus.man wumpus.man.old
11 8:36 vi wumpus.man
12 8:37 diff wumpus.man.old wumpus.man
The commands are shown with their event numbers and time stamps. The
current event, which we haven’t typed in yet, is event 13. ‘!11’ and
‘!-2’ refer to event 11. ‘!!’ refers to the previous event, 12. ‘!!’
can be abbreviated ‘!’ if it is followed by ‘:’ (‘:’ is described
below). ‘!n’ refers to event 9, which begins with ‘n’. ‘!?old?’ also
refers to event 12, which contains ‘old’. Without word designators or
modifiers history references simply expand to the entire event, so we
might type ‘!cp’ to redo the copy command or ‘!!|more’ if the ‘diff’
output scrolled off the top of the screen.
History references may be insulated from the surrounding text with
braces if necessary. For example, ‘!vdoc’ would look for a command
beginning with ‘vdoc’, and, in this example, not find one, but
‘!{v}doc’ would expand unambiguously to ‘vi wumpus.mandoc’. Even in
braces, history substitutions do not nest.
(+) While csh(1) expands, for example, ‘!3d’ to event 3 with the letter
‘d’ appended to it, tcsh expands it to the last event beginning with
‘3d’; only completely numeric arguments are treated as event numbers.
This makes it possible to recall events beginning with numbers. To
expand ‘!3d’ as in csh(1) say ‘!{3}d’.
To select words from an event we can follow the event specification by
a ‘:’ and a designator for the desired words. The words of an input
line are numbered from 0, the first (usually command) word being 0, the
second word (first argument) being 1, etc. The basic word designators
are:
0 The first (command) word
n The nth argument
^ The first argument, equivalent to ‘1’
$ The last argument
% The word matched by an ?s? search
x-y A range of words
-y Equivalent to ‘0-y’
* Equivalent to ‘^-$’, but returns nothing if the event con-
tains only 1 word
x* Equivalent to ‘x-$’
x- Equivalent to ‘x*’, but omitting the last word (‘$’)
Selected words are inserted into the command line separated by single
blanks. For example, the ‘diff’ command in the previous example might
have been typed as ‘diff !!:1.old !!:1’ (using ‘:1’ to select the first
argument from the previous event) or ‘diff !-2:2 !-2:1’ to select and
swap the arguments from the ‘cp’ command. If we didn’t care about the
order of the ‘diff’ we might have said ‘diff !-2:1-2’ or simply ‘diff
!-2:*’. The ‘cp’ command might have been written ‘cp wumpus.man
!#:1.old’, using ‘#’ to refer to the current event. ‘!n:- hurkle.man’
would reuse the first two words from the ‘nroff’ command to say ‘nroff
-man hurkle.man’.
The ‘:’ separating the event specification from the word designator can
be omitted if the argument selector begins with a ‘^’, ‘$’, ‘*’, ‘%’ or
‘-’. For example, our ‘diff’ command might have been ‘diff !!^.old
!!^’ or, equivalently, ‘diff !!$.old !!$’. However, if ‘!!’ is abbre-
viated ‘!’, an argument selector beginning with ‘-’ will be interpreted
as an event specification.
A history reference may have a word designator but no event specifica-
tion. It then references the previous command. Continuing our ‘diff’
example, we could have said simply ‘diff !^.old !^’ or, to get the
arguments in the opposite order, just ‘diff !*’.
The word or words in a history reference can be edited, or ‘‘modi-
fied’’, by following it with one or more modifiers, each preceded by a
‘:’:
h Remove a trailing pathname component, leaving the head.
t Remove all leading pathname components, leaving the tail.
r Remove a filename extension ‘.xxx’, leaving the root name.
e Remove all but the extension.
u Uppercase the first lowercase letter.
l Lowercase the first uppercase letter.
s/l/r/ Substitute l for r. l is simply a string like r, not a
regular expression as in the eponymous ed(1) command. Any
character may be used as the delimiter in place of ‘/’; a
‘\’ can be used to quote the delimiter expect ‘(’, ‘)’, ‘|’
and ‘>’ inside l and r. The character ‘&’ in the r is
replaced by l; ‘\’ also quotes ‘&’. If l is empty (‘‘’’),
the l from a previous substitution or the s from a previous
search or event number in event specification is used. The
trailing delimiter may be omitted if it is immediately fol-
lowed by a newline.
& Repeat the previous substitution.
g Apply the following modifier once to each word.
a (+) Apply the following modifier as many times as possible to a
single word. ‘a’ and ‘g’ can be used together to apply a
modifier globally. With the ‘s’ modifier, only the pat-
terns contained in the original word are substituted, not
patterns that contain any substitution result.
p Print the new command line but do not execute it.
q Quote the substituted words, preventing further substitu-
tions.
x Like q, but break into words at blanks, tabs and newlines.
Modifiers are applied to only the first modifiable word (unless ‘g’ is
used). It is an error for no word to be modifiable.
For example, the ‘diff’ command might have been written as ‘diff wum-
pus.man.old !#^:r’, using ‘:r’ to remove ‘.old’ from the first argument
on the same line (‘!#^’). We could say ‘echo hello out there’, then
‘echo !*:u’ to capitalize ‘hello’, ‘echo !*:au’ to say it out loud, or
‘echo !*:agu’ to really shout. We might follow ‘mail -s "I forgot my
password" rot’ with ‘!:s/rot/root’ to correct the spelling of ‘root’
(but see Spelling correction for a different approach).
There is a special abbreviation for substitutions. ‘^’, when it is the
first character on an input line, is equivalent to ‘!:s^’. Thus we
might have said ‘^rot^root’ to make the spelling correction in the pre-
vious example. This is the only history substitution which does not
explicitly begin with ‘!’.
(+) In csh as such, only one modifier may be applied to each history or
variable expansion. In tcsh, more than one may be used, for example
% mv wumpus.man /usr/man/man1/wumpus.1
% man !$:t:r
man wumpus
In csh, the result would be ‘wumpus.1:r’. A substitution followed by a
colon may need to be insulated from it with braces:
> mv a.out /usr/games/wumpus
> setenv PATH !$:h:$PATH
Bad ! modifier: $.
> setenv PATH !{-2$:h}:$PATH
setenv PATH /usr/games:/bin:/usr/bin:.
The first attempt would succeed in csh but fails in tcsh, because tcsh
expects another modifier after the second colon rather than ‘$’.
Finally, history can be accessed through the editor as well as through
the substitutions just described. The up- and down-history, history-
search-backward and -forward, i-search-back and -fwd, vi-search-back
and -fwd, copy-prev-word and insert-last-word editor commands search
for events in the history list and copy them into the input buffer.
The toggle-literal-history editor command switches between the expanded
and literal forms of history lines in the input buffer. expand-history
and expand-line expand history substitutions in the current word and in
the entire input buffer respectively.
Alias substitution
The shell maintains a list of aliases which can be set, unset and
printed by the alias and unalias commands. After a command line is
parsed into simple commands (see Commands) the first word of each com-
mand, left-to-right, is checked to see if it has an alias. If so, the
first word is replaced by the alias. If the alias contains a history
reference, it undergoes History substitution (q.v.) as though the orig-
inal command were the previous input line. If the alias does not con-
tain a history reference, the argument list is left untouched.
Thus if the alias for ‘ls’ were ‘ls -l’ the command ‘ls /usr’ would
become ‘ls -l /usr’, the argument list here being undisturbed. If the
alias for ‘lookup’ were ‘grep !^ /etc/passwd’ then ‘lookup bill’ would
become ‘grep bill /etc/passwd’. Aliases can be used to introduce
parser metasyntax. For example, ‘alias print ’pr \!* | lpr’’ defines a
‘‘command’’ (‘print’) which pr(1)s its arguments to the line printer.
Alias substitution is repeated until the first word of the command has
no alias. If an alias substitution does not change the first word (as
in the previous example) it is flagged to prevent a loop. Other loops
are detected and cause an error.
Some aliases are referred to by the shell; see Special aliases.
Variable substitution
The shell maintains a list of variables, each of which has as value a
list of zero or more words. The values of shell variables can be dis-
played and changed with the set and unset commands. The system main-
tains its own list of ‘‘environment’’ variables. These can be dis-
played and changed with printenv, setenv and unsetenv.
(+) Variables may be made read-only with ‘set -r’ (q.v.) Read-only
variables may not be modified or unset; attempting to do so will cause
an error. Once made read-only, a variable cannot be made writable, so
‘set -r’ should be used with caution. Environment variables cannot be
made read-only.
Some variables are set by the shell or referred to by it. For
instance, the argv variable is an image of the shell’s argument list,
and words of this variable’s value are referred to in special ways.
Some of the variables referred to by the shell are toggles; the shell
does not care what their value is, only whether they are set or not.
For instance, the verbose variable is a toggle which causes command
input to be echoed. The -v command line option sets this variable.
Special shell variables lists all variables which are referred to by
the shell.
Other operations treat variables numerically. The ‘@’ command permits
numeric calculations to be performed and the result assigned to a vari-
able. Variable values are, however, always represented as (zero or
more) strings. For the purposes of numeric operations, the null string
is considered to be zero, and the second and subsequent words of multi-
word values are ignored.
After the input line is aliased and parsed, and before each command is
executed, variable substitution is performed keyed by ‘$’ characters.
This expansion can be prevented by preceding the ‘$’ with a ‘\’ except
within ‘"’s where it always occurs, and within ‘’’s where it never
occurs. Strings quoted by ‘‘’ are interpreted later (see Command sub-
stitution below) so ‘$’ substitution does not occur there until later,
if at all. A ‘$’ is passed unchanged if followed by a blank, tab, or
end-of-line.
Input/output redirections are recognized before variable expansion, and
are variable expanded separately. Otherwise, the command name and
entire argument list are expanded together. It is thus possible for
the first (command) word (to this point) to generate more than one
word, the first of which becomes the command name, and the rest of
which become arguments.
Unless enclosed in ‘"’ or given the ‘:q’ modifier the results of vari-
able substitution may eventually be command and filename substituted.
Within ‘"’, a variable whose value consists of multiple words expands
to a (portion of a) single word, with the words of the variable’s value
separated by blanks. When the ‘:q’ modifier is applied to a substitu-
tion the variable will expand to multiple words with each word sepa-
rated by a blank and quoted to prevent later command or filename sub-
stitution.
The following metasequences are provided for introducing variable val-
ues into the shell input. Except as noted, it is an error to reference
a variable which is not set.
$name
${name} Substitutes the words of the value of variable name, each sepa-
rated by a blank. Braces insulate name from following charac-
ters which would otherwise be part of it. Shell variables have
names consisting of letters and digits starting with a letter.
The underscore character is considered a letter. If name is
not a shell variable, but is set in the environment, then that
value is returned (but some of the other forms given below are
not available in this case).
$name[selector]
${name[selector]}
Substitutes only the selected words from the value of name.
The selector is subjected to ‘$’ substitution and may consist
of a single number or two numbers separated by a ‘-’. The
first word of a variable’s value is numbered ‘1’. If the first
number of a range is omitted it defaults to ‘1’. If the last
member of a range is omitted it defaults to ‘$#name’. The
selector ‘*’ selects all words. It is not an error for a range
to be empty if the second argument is omitted or in range.
$0 Substitutes the name of the file from which command input is
being read. An error occurs if the name is not known.
$number
${number}
Equivalent to ‘$argv[number]’.
$* Equivalent to ‘$argv’, which is equivalent to ‘$argv[*]’.
The ‘:’ modifiers described under History substitution, except for
‘:p’, can be applied to the substitutions above. More than one may be
used. (+) Braces may be needed to insulate a variable substitution
from a literal colon just as with History substitution (q.v.); any mod-
ifiers must appear within the braces.
The following substitutions can not be modified with ‘:’ modifiers.
$?name
${?name}
Substitutes the string ‘1’ if name is set, ‘0’ if it is not.
$?0 Substitutes ‘1’ if the current input filename is known, ‘0’ if
it is not. Always ‘0’ in interactive shells.
$#name
${#name}
Substitutes the number of words in name.
$# Equivalent to ‘$#argv’. (+)
$%name
${%name}
Substitutes the number of characters in name. (+)
$%number
${%number}
Substitutes the number of characters in $argv[number]. (+)
$? Equivalent to ‘$status’. (+)
$$ Substitutes the (decimal) process number of the (parent) shell.
$! Substitutes the (decimal) process number of the last background
process started by this shell. (+)
$_ Substitutes the command line of the last command executed. (+)
$< Substitutes a line from the standard input, with no further
interpretation thereafter. It can be used to read from the
keyboard in a shell script. (+) While csh always quotes $<, as
if it were equivalent to ‘$<:q’, tcsh does not. Furthermore,
when tcsh is waiting for a line to be typed the user may type
an interrupt to interrupt the sequence into which the line is
to be substituted, but csh does not allow this.
The editor command expand-variables, normally bound to ‘^X-$’, can be
used to interactively expand individual variables.
Command, filename and directory stack substitution
The remaining substitutions are applied selectively to the arguments of
builtin commands. This means that portions of expressions which are
not evaluated are not subjected to these expansions. For commands
which are not internal to the shell, the command name is substituted
separately from the argument list. This occurs very late, after input-
output redirection is performed, and in a child of the main shell.
Command substitution
Command substitution is indicated by a command enclosed in ‘‘’. The
output from such a command is broken into separate words at blanks,
tabs and newlines, and null words are discarded. The output is vari-
able and command substituted and put in place of the original string.
Command substitutions inside double quotes (‘"’) retain blanks and
tabs; only newlines force new words. The single final newline does not
force a new word in any case. It is thus possible for a command sub-
stitution to yield only part of a word, even if the command outputs a
complete line.
By default, the shell since version 6.12 replaces all newline and car-
riage return characters in the command by spaces. If this is switched
off by unsetting csubstnonl, newlines separate commands as usual.
Filename substitution
If a word contains any of the characters ‘*’, ‘?’, ‘[’ or ‘{’ or begins
with the character ‘~’ it is a candidate for filename substitution,
also known as ‘‘globbing’’. This word is then regarded as a pattern
(‘‘glob-pattern’’), and replaced with an alphabetically sorted list of
file names which match the pattern.
In matching filenames, the character ‘.’ at the beginning of a filename
or immediately following a ‘/’, as well as the character ‘/’ must be
matched explicitly. The character ‘*’ matches any string of charac-
ters, including the null string. The character ‘?’ matches any single
character. The sequence ‘[...]’ matches any one of the characters
enclosed. Within ‘[...]’, a pair of characters separated by ‘-’
matches any character lexically between the two.
(+) Some glob-patterns can be negated: The sequence ‘[^...]’ matches
any single character not specified by the characters and/or ranges of
characters in the braces.
An entire glob-pattern can also be negated with ‘^’:
> echo *
bang crash crunch ouch
> echo ^cr*
bang ouch
Glob-patterns which do not use ‘?’, ‘*’, or ‘[]’ or which use ‘{}’ or
‘~’ (below) are not negated correctly.
The metanotation ‘a{b,c,d}e’ is a shorthand for ‘abe ace ade’. Left-
to-right order is preserved: ‘/usr/source/s1/{oldls,ls}.c’ expands to
‘/usr/source/s1/oldls.c /usr/source/s1/ls.c’. The results of matches
are sorted separately at a low level to preserve this order:
‘../{memo,*box}’ might expand to ‘../memo ../box ../mbox’. (Note that
‘memo’ was not sorted with the results of matching ‘*box’.) It is not
an error when this construct expands to files which do not exist, but
it is possible to get an error from a command to which the expanded
list is passed. This construct may be nested. As a special case the
words ‘{’, ‘}’ and ‘{}’ are passed undisturbed.
The character ‘~’ at the beginning of a filename refers to home direc-
tories. Standing alone, i.e., ‘~’, it expands to the invoker’s home
directory as reflected in the value of the home shell variable. When
followed by a name consisting of letters, digits and ‘-’ characters the
shell searches for a user with that name and substitutes their home
directory; thus ‘~ken’ might expand to ‘/usr/ken’ and ‘~ken/chmach’ to
‘/usr/ken/chmach’. If the character ‘~’ is followed by a character
other than a letter or ‘/’ or appears elsewhere than at the beginning
of a word, it is left undisturbed. A command like ‘setenv MANPATH
/usr/man:/usr/local/man:~/lib/man’ does not, therefore, do home direc-
tory substitution as one might hope.
It is an error for a glob-pattern containing ‘*’, ‘?’, ‘[’ or ‘~’, with
or without ‘^’, not to match any files. However, only one pattern in a
list of glob-patterns must match a file (so that, e.g., ‘rm *.a *.c
*.o’ would fail only if there were no files in the current directory
ending in ‘.a’, ‘.c’, or ‘.o’), and if the nonomatch shell variable is
set a pattern (or list of patterns) which matches nothing is left
unchanged rather than causing an error.
The noglob shell variable can be set to prevent filename substitution,
and the expand-glob editor command, normally bound to ‘^X-*’, can be
used to interactively expand individual filename substitutions.
Directory stack substitution (+)
The directory stack is a list of directories, numbered from zero, used
by the pushd, popd and dirs builtin commands (q.v.). dirs can print,
store in a file, restore and clear the directory stack at any time, and
the savedirs and dirsfile shell variables can be set to store the
directory stack automatically on logout and restore it on login. The
dirstack shell variable can be examined to see the directory stack and
set to put arbitrary directories into the directory stack.
The character ‘=’ followed by one or more digits expands to an entry in
the directory stack. The special case ‘=-’ expands to the last direc-
tory in the stack. For example,
> dirs -v
0 /usr/bin
1 /usr/spool/uucp
2 /usr/accts/sys
> echo =1
/usr/spool/uucp
> echo =0/calendar
/usr/bin/calendar
> echo =-
/usr/accts/sys
The noglob and nonomatch shell variables and the expand-glob editor
command apply to directory stack as well as filename substitutions.
Other substitutions (+)
There are several more transformations involving filenames, not
strictly related to the above but mentioned here for completeness. Any
filename may be expanded to a full path when the symlinks variable
(q.v.) is set to ‘expand’. Quoting prevents this expansion, and the
normalize-path editor command does it on demand. The normalize-command
editor command expands commands in PATH into full paths on demand.
Finally, cd and pushd interpret ‘-’ as the old working directory
(equivalent to the shell variable owd). This is not a substitution at
all, but an abbreviation recognized by only those commands. Nonethe-
less, it too can be prevented by quoting.
Commands
The next three sections describe how the shell executes commands and
deals with their input and output.
Simple commands, pipelines and sequences
A simple command is a sequence of words, the first of which specifies
the command to be executed. A series of simple commands joined by ‘|’
characters forms a pipeline. The output of each command in a pipeline
is connected to the input of the next.
Simple commands and pipelines may be joined into sequences with ‘;’,
and will be executed sequentially. Commands and pipelines can also be
joined into sequences with ‘||’ or ‘&&’, indicating, as in the C lan-
guage, that the second is to be executed only if the first fails or
succeeds respectively.
A simple command, pipeline or sequence may be placed in parentheses,
‘()’, to form a simple command, which may in turn be a component of a
pipeline or sequence. A command, pipeline or sequence can be executed
without waiting for it to terminate by following it with an ‘&’.
Builtin and non-builtin command execution
Builtin commands are executed within the shell. If any component of a
pipeline except the last is a builtin command, the pipeline is executed
in a subshell.
Parenthesized commands are always executed in a subshell.
(cd; pwd); pwd
thus prints the home directory, leaving you where you were (printing
this after the home directory), while
cd; pwd
leaves you in the home directory. Parenthesized commands are most
often used to prevent cd from affecting the current shell.
When a command to be executed is found not to be a builtin command the
shell attempts to execute the command via execve(2). Each word in the
variable path names a directory in which the shell will look for the
command. If the shell is not given a -f option, the shell hashes the
names in these directories into an internal table so that it will try
an execve(2) in only a directory where there is a possibility that the
command resides there. This greatly speeds command location when a
large number of directories are present in the search path. This hash-
ing mechanism is not used:
1. If hashing is turned explicitly off via unhash.
2. If the shell was given a -f argument.
3. For each directory component of path which does not begin with a
‘/’.
4. If the command contains a ‘/’.
In the above four cases the shell concatenates each component of the
path vector with the given command name to form a path name of a file
which it then attempts to execute it. If execution is successful, the
search stops.
If the file has execute permissions but is not an executable to the
system (i.e., it is neither an executable binary nor a script that
specifies its interpreter), then it is assumed to be a file containing
shell commands and a new shell is spawned to read it. The shell spe-
cial alias may be set to specify an interpreter other than the shell
itself.
On systems which do not understand the ‘#!’ script interpreter conven-
tion the shell may be compiled to emulate it; see the version shell
variable. If so, the shell checks the first line of the file to see if
it is of the form ‘#!interpreter arg ...’. If it is, the shell starts
interpreter with the given args and feeds the file to it on standard
input.
Input/output
The standard input and standard output of a command may be redirected
with the following syntax:
< name Open file name (which is first variable, command and filename
expanded) as the standard input.
<< word Read the shell input up to a line which is identical to word.
word is not subjected to variable, filename or command substi-
tution, and each input line is compared to word before any sub-
stitutions are done on this input line. Unless a quoting ‘\’,
‘"’, ‘’ or ‘‘’ appears in word variable and command substitu-
tion is performed on the intervening lines, allowing ‘\’ to
quote ‘$’, ‘\’ and ‘‘’. Commands which are substituted have
all blanks, tabs, and newlines preserved, except for the final
newline which is dropped. The resultant text is placed in an
anonymous temporary file which is given to the command as stan-
dard input.
> name
>! name
>& name
>&! name
The file name is used as standard output. If the file does not
exist then it is created; if the file exists, it is truncated,
its previous contents being lost.
If the shell variable noclobber is set, then the file must not
exist or be a character special file (e.g., a terminal or
‘/dev/null’) or an error results. This helps prevent acciden-
tal destruction of files. In this case the ‘!’ forms can be
used to suppress this check.
The forms involving ‘&’ route the diagnostic output into the
specified file as well as the standard output. name is
expanded in the same way as ‘<’ input filenames are.
>> name
>>& name
>>! name
>>&! name
Like ‘>’, but appends output to the end of name. If the shell
variable noclobber is set, then it is an error for the file not
to exist, unless one of the ‘!’ forms is given.
A command receives the environment in which the shell was invoked as
modified by the input-output parameters and the presence of the command
in a pipeline. Thus, unlike some previous shells, commands run from a
file of shell commands have no access to the text of the commands by
default; rather they receive the original standard input of the shell.
The ‘<<’ mechanism should be used to present inline data. This permits
shell command scripts to function as components of pipelines and allows
the shell to block read its input. Note that the default standard
input for a command run detached is not the empty file /dev/null, but
the original standard input of the shell. If this is a terminal and if
the process attempts to read from the terminal, then the process will
block and the user will be notified (see Jobs).
Diagnostic output may be directed through a pipe with the standard
output. Simply use the form ‘|&’ rather than just ‘|’.
The shell cannot presently redirect diagnostic output without also
redirecting standard output, but ‘(command > output-file) >& error-
file’ is often an acceptable workaround. Either output-file or error-
file may be ‘/dev/tty’ to send output to the terminal.
Features
Having described how the shell accepts, parses and executes command
lines, we now turn to a variety of its useful features.
Control flow
The shell contains a number of commands which can be used to regulate
the flow of control in command files (shell scripts) and (in limited
but useful ways) from terminal input. These commands all operate by
forcing the shell to reread or skip in its input and, due to the imple-
mentation, restrict the placement of some of the commands.
The foreach, switch, and while statements, as well as the if-then-else
form of the if statement, require that the major keywords appear in a
single simple command on an input line as shown below.
If the shell’s input is not seekable, the shell buffers up input when-
ever a loop is being read and performs seeks in this internal buffer to
accomplish the rereading implied by the loop. (To the extent that this
allows, backward gotos will succeed on non-seekable inputs.)
Expressions
The if, while and exit builtin commands use expressions with a common
syntax. The expressions can include any of the operators described in
the next three sections. Note that the @ builtin command (q.v.) has
its own separate syntax.
Logical, arithmetical and comparison operators
These operators are similar to those of C and have the same precedence.
They include
|| && | ^ & == != =~ !~ <= >=
< > << >> + - * / % ! ~ ( )
Here the precedence increases to the right, ‘==’ ‘!=’ ‘=~’ and ‘!~’,
‘<=’ ‘>=’ ‘<’ and ‘>’, ‘<<’ and ‘>>’, ‘+’ and ‘-’, ‘*’ ‘/’ and ‘%’
being, in groups, at the same level. When multiple operators which
have same precedence are used in one expression, calculation must be
done from operator of right side. The ‘==’ ‘!=’ ‘=~’ and ‘!~’ opera-
tors compare their arguments as strings; all others operate on numbers.
The operators ‘=~’ and ‘!~’ are like ‘!=’ and ‘==’ except that the
right hand side is a glob-pattern (see Filename substitution) against
which the left hand operand is matched. This reduces the need for use
of the switch builtin command in shell scripts when all that is really
needed is pattern matching.
Null or missing arguments are considered ‘0’. The results of all
expressions are strings, which represent decimal numbers. It is impor-
tant to note that no two components of an expression can appear in the
same word; except when adjacent to components of expressions which are
syntactically significant to the parser (‘&’ ‘|’ ‘<’ ‘>’ ‘(’ ‘)’) they
should be surrounded by spaces.
Command exit status
Commands can be executed in expressions and their exit status returned
by enclosing them in braces (‘{}’). Remember that the braces should be
separated from the words of the command by spaces. Command executions
succeed, returning true, i.e., ‘1’, if the command exits with status 0,
otherwise they fail, returning false, i.e., ‘0’. If more detailed sta-
tus information is required then the command should be executed outside
of an expression and the status shell variable examined.
File inquiry operators
Some of these operators perform true/false tests on files and related
objects. They are of the form -op file, where op is one of
r Read access
w Write access
x Execute access
X Executable in the path or shell builtin, e.g., ‘-X ls’ and ‘-X
ls-F’ are generally true, but ‘-X /bin/ls’ is not (+)
e Existence
o Ownership
z Zero size
s Non-zero size (+)
f Plain file
d Directory
l Symbolic link (+) *
b Block special file (+)
c Character special file (+)
p Named pipe (fifo) (+) *
S Socket special file (+) *
u Set-user-ID bit is set (+)
g Set-group-ID bit is set (+)
k Sticky bit is set (+)
t file (which must be a digit) is an open file descriptor for a
terminal device (+)
R Has been migrated (convex only) (+)
L Applies subsequent operators in a multiple-operator test to a
symbolic link rather than to the file to which the link points
(+) *
file is command and filename expanded and then tested to see if it has
the specified relationship to the real user. If file does not exist or
is inaccessible or, for the operators indicated by ‘*’, if the speci-
fied file type does not exist on the current system, then all enquiries
return false, i.e., ‘0’.
These operators may be combined for conciseness: ‘-xy file’ is equiva-
lent to ‘-x file && -y file’. (+) For example, ‘-fx’ is true (returns
‘1’) for plain executable files, but not for directories.
L may be used in a multiple-operator test to apply subsequent operators
to a symbolic link rather than to the file to which the link points.
For example, ‘-lLo’ is true for links owned by the invoking user. Lr,
Lw and Lx are always true for links and false for non-links. L has a
different meaning when it is the last operator in a multiple-operator
test; see below.
It is possible but not useful, and sometimes misleading, to combine
operators which expect file to be a file with operators which do not,
(e.g., X and t). Following L with a non-file operator can lead to par-
ticularly strange results.
Other operators return other information, i.e., not just ‘0’ or ‘1’.
(+) They have the same format as before; op may be one of
A Last file access time, as the number of seconds since the
epoch
A: Like A, but in timestamp format, e.g., ‘Fri May 14 16:36:10
1993’
M Last file modification time
M: Like M, but in timestamp format
C Last inode modification time
C: Like C, but in timestamp format
D Device number
I Inode number
F Composite file identifier, in the form device:inode
L The name of the file pointed to by a symbolic link
N Number of (hard) links
P Permissions, in octal, without leading zero
P: Like P, with leading zero
Pmode Equivalent to ‘-P file & mode’, e.g., ‘-P22 file’ returns
‘22’ if file is writable by group and other, ‘20’ if by
group only, and ‘0’ if by neither
Pmode: Like Pmode, with leading zero
U Numeric userid
U: Username, or the numeric userid if the username is unknown
G Numeric groupid
G: Groupname, or the numeric groupid if the groupname is
unknown
Z Size, in bytes
Only one of these operators may appear in a multiple-operator test, and
it must be the last. Note that L has a different meaning at the end of
and elsewhere in a multiple-operator test. Because ‘0’ is a valid
return value for many of these operators, they do not return ‘0’ when
they fail: most return ‘-1’, and F returns ‘:’.
If the shell is compiled with POSIX defined (see the version shell
variable), the result of a file inquiry is based on the permission bits
of the file and not on the result of the access(2) system call. For
example, if one tests a file with -w whose permissions would ordinarily
allow writing but which is on a file system mounted read-only, the test
will succeed in a POSIX shell but fail in a non-POSIX shell.
File inquiry operators can also be evaluated with the filetest builtin
command (q.v.) (+).
Jobs
The shell associates a job with each pipeline. It keeps a table of
current jobs, printed by the jobs command, and assigns them small inte-
ger numbers. When a job is started asynchronously with ‘&’, the shell
prints a line which looks like
[1] 1234
indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process id was 1234.
If you are running a job and wish to do something else you may hit the
suspend key (usually ‘^Z’), which sends a STOP signal to the current
job. The shell will then normally indicate that the job has been ‘Sus-
pended’ and print another prompt. If the listjobs shell variable is
set, all jobs will be listed like the jobs builtin command; if it is
set to ‘long’ the listing will be in long format, like ‘jobs -l’. You
can then manipulate the state of the suspended job. You can put it in
the ‘‘background’’ with the bg command or run some other commands and
eventually bring the job back into the ‘‘foreground’’ with fg. (See
also the run-fg-editor editor command.) A ‘^Z’ takes effect immedi-
ately and is like an interrupt in that pending output and unread input
are discarded when it is typed. The wait builtin command causes the
shell to wait for all background jobs to complete.
The ‘^]’ key sends a delayed suspend signal, which does not generate a
STOP signal until a program attempts to read(2) it, to the current job.
This can usefully be typed ahead when you have prepared some commands
for a job which you wish to stop after it has read them. The ‘^Y’ key
performs this function in csh(1); in tcsh, ‘^Y’ is an editing command.
(+)
A job being run in the background stops if it tries to read from the
terminal. Background jobs are normally allowed to produce output, but
this can be disabled by giving the command ‘stty tostop’. If you set
this tty option, then background jobs will stop when they try to pro-
duce output like they do when they try to read input.
There are several ways to refer to jobs in the shell. The character
‘%’ introduces a job name. If you wish to refer to job number 1, you
can name it as ‘%1’. Just naming a job brings it to the foreground;
thus ‘%1’ is a synonym for ‘fg %1’, bringing job 1 back into the fore-
ground. Similarly, saying ‘%1 &’ resumes job 1 in the background, just
like ‘bg %1’. A job can also be named by an unambiguous prefix of the
string typed in to start it: ‘%ex’ would normally restart a suspended
ex(1) job, if there were only one suspended job whose name began with
the string ‘ex’. It is also possible to say ‘%?string’ to specify a
job whose text contains string, if there is only one such job.
The shell maintains a notion of the current and previous jobs. In out-
put pertaining to jobs, the current job is marked with a ‘+’ and the
previous job with a ‘-’. The abbreviations ‘%+’, ‘%’, and (by analogy
with the syntax of the history mechanism) ‘%%’ all refer to the current
job, and ‘%-’ refers to the previous job.
The job control mechanism requires that the stty(1) option ‘new’ be set
on some systems. It is an artifact from a ‘new’ implementation of the
tty driver which allows generation of interrupt characters from the
keyboard to tell jobs to stop. See stty(1) and the setty builtin com-
mand for details on setting options in the new tty driver.
Status reporting
The shell learns immediately whenever a process changes state. It nor-
mally informs you whenever a job becomes blocked so that no further
progress is possible, but only right before it prints a prompt. This
is done so that it does not otherwise disturb your work. If, however,
you set the shell variable notify, the shell will notify you immedi-
ately of changes of status in background jobs. There is also a shell
command notify which marks a single process so that its status changes
will be immediately reported. By default notify marks the current pro-
cess; simply say ‘notify’ after starting a background job to mark it.
When you try to leave the shell while jobs are stopped, you will be
warned that ‘There are suspended jobs.’ You may use the jobs command to
see what they are. If you do this or immediately try to exit again,
the shell will not warn you a second time, and the suspended jobs will
be terminated.
Automatic, periodic and timed events (+)
There are various ways to run commands and take other actions automati-
cally at various times in the ‘‘life cycle’’ of the shell. They are
summarized here, and described in detail under the appropriate Builtin
commands, Special shell variables and Special aliases.
The sched builtin command puts commands in a scheduled-event list, to
be executed by the shell at a given time.
The beepcmd, cwdcmd, periodic, precmd, postcmd, and jobcmd Special
aliases can be set, respectively, to execute commands when the shell
wants to ring the bell, when the working directory changes, every tpe-
riod minutes, before each prompt, before each command gets executed,
after each command gets executed, and when a job is started or is
brought into the foreground.
The autologout shell variable can be set to log out or lock the shell
after a given number of minutes of inactivity.
The mail shell variable can be set to check for new mail periodically.
The printexitvalue shell variable can be set to print the exit status
of commands which exit with a status other than zero.
The rmstar shell variable can be set to ask the user, when ‘rm *’ is
typed, if that is really what was meant.
The time shell variable can be set to execute the time builtin command
after the completion of any process that takes more than a given number
of CPU seconds.
The watch and who shell variables can be set to report when selected
users log in or out, and the log builtin command reports on those users
at any time.
Native Language System support (+)
The shell is eight bit clean (if so compiled; see the version shell
variable) and thus supports character sets needing this capability.
NLS support differs depending on whether or not the shell was compiled
to use the system’s NLS (again, see version). In either case, 7-bit
ASCII is the default character code (e.g., the classification of which
characters are printable) and sorting, and changing the LANG or
LC_CTYPE environment variables causes a check for possible changes in
these respects.
When using the system’s NLS, the setlocale(3) function is called to
determine appropriate character code/classification and sorting (e.g.,
a ’en_CA.UTF-8’ would yield "UTF-8" as a character code). This func-
tion typically examines the LANG and LC_CTYPE environment variables;
refer to the system documentation for further details. When not using
the system’s NLS, the shell simulates it by assuming that the ISO
8859-1 character set is used whenever either of the LANG and LC_CTYPE
variables are set, regardless of their values. Sorting is not affected
for the simulated NLS.
In addition, with both real and simulated NLS, all printable characters
in the range \200-\377, i.e., those that have M-char bindings, are
automatically rebound to self-insert-command. The corresponding bind-
ing for the escape-char sequence, if any, is left alone. These charac-
ters are not rebound if the NOREBIND environment variable is set. This
may be useful for the simulated NLS or a primitive real NLS which
assumes full ISO 8859-1. Otherwise, all M-char bindings in the range
\240-\377 are effectively undone. Explicitly rebinding the relevant
keys with bindkey is of course still possible.
Unknown characters (i.e., those that are neither printable nor control
characters) are printed in the format \nnn. If the tty is not in 8 bit
mode, other 8 bit characters are printed by converting them to ASCII
and using standout mode. The shell never changes the 7/8 bit mode of
the tty and tracks user-initiated changes of 7/8 bit mode. NLS users
(or, for that matter, those who want to use a meta key) may need to
explicitly set the tty in 8 bit mode through the appropriate stty(1)
command in, e.g., the ~/.login file.
OS variant support (+)
A number of new builtin commands are provided to support features in
particular operating systems. All are described in detail in the
Builtin commands section.
On systems that support TCF (aix-ibm370, aix-ps2), getspath and
setspath get and set the system execution path, getxvers and setxvers
get and set the experimental version prefix and migrate migrates pro-
cesses between sites. The jobs builtin prints the site on which each
job is executing.
Under BS2000, bs2cmd executes commands of the underlying BS2000/OSD
operating system.
Under Domain/OS, inlib adds shared libraries to the current environ-
ment, rootnode changes the rootnode and ver changes the systype.
Under Mach, setpath is equivalent to Mach’s setpath(1).
Under Masscomp/RTU and Harris CX/UX, universe sets the universe.
Under Harris CX/UX, ucb or att runs a command under the specified uni-
verse.
Under Convex/OS, warp prints or sets the universe.
The VENDOR, OSTYPE and MACHTYPE environment variables indicate respec-
tively the vendor, operating system and machine type (microprocessor
class or machine model) of the system on which the shell thinks it is
running. These are particularly useful when sharing one’s home direc-
tory between several types of machines; one can, for example,
set path = (~/bin.$MACHTYPE /usr/ucb /bin /usr/bin .)
in one’s ~/.login and put executables compiled for each machine in the
appropriate directory.
The version shell variable indicates what options were chosen when the
shell was compiled.
Note also the newgrp builtin, the afsuser and echo_style shell vari-
ables and the system-dependent locations of the shell’s input files
(see FILES).
Signal handling
Login shells ignore interrupts when reading the file ~/.logout. The
shell ignores quit signals unless started with -q. Login shells catch
the terminate signal, but non-login shells inherit the terminate behav-
ior from their parents. Other signals have the values which the shell
inherited from its parent.
In shell scripts, the shell’s handling of interrupt and terminate sig-
nals can be controlled with onintr, and its handling of hangups can be
controlled with hup and nohup.
The shell exits on a hangup (see also the logout shell variable). By
default, the shell’s children do too, but the shell does not send them
a hangup when it exits. hup arranges for the shell to send a hangup to
a child when it exits, and nohup sets a child to ignore hangups.
Terminal management (+)
The shell uses three different sets of terminal (‘‘tty’’) modes:
‘edit’, used when editing, ‘quote’, used when quoting literal charac-
ters, and ‘execute’, used when executing commands. The shell holds
some settings in each mode constant, so commands which leave the tty in
a confused state do not interfere with the shell. The shell also
matches changes in the speed and padding of the tty. The list of tty
modes that are kept constant can be examined and modified with the
setty builtin. Note that although the editor uses CBREAK mode (or its
equivalent), it takes typed-ahead characters anyway.
The echotc, settc and telltc commands can be used to manipulate and
debug terminal capabilities from the command line.
On systems that support SIGWINCH or SIGWINDOW, the shell adapts to win-
dow resizing automatically and adjusts the environment variables LINES
and COLUMNS if set. If the environment variable TERMCAP contains li#
and co# fields, the shell adjusts them to reflect the new window size.
REFERENCE
The next sections of this manual describe all of the available Builtin
commands, Special aliases and Special shell variables.
Builtin commands
%job A synonym for the fg builtin command.
%job & A synonym for the bg builtin command.
: Does nothing, successfully.
@
@ name = expr
@ name[index] = expr
@ name++|--
@ name[index]++|--
The first form prints the values of all shell variables.
The second form assigns the value of expr to name. The third
form assigns the value of expr to the index’th component of
name; both name and its index’th component must already exist.
expr may contain the operators ‘*’, ‘+’, etc., as in C. If
expr contains ‘<’, ‘>’, ‘&’ or ‘’ then at least that part of
expr must be placed within ‘()’. Note that the syntax of expr
has nothing to do with that described under Expressions.
The fourth and fifth forms increment (‘++’) or decrement (‘--’)
name or its index’th component.
The space between ‘@’ and name is required. The spaces between
name and ‘=’ and between ‘=’ and expr are optional. Components
of expr must be separated by spaces.
alias [name [wordlist]]
Without arguments, prints all aliases. With name, prints the
alias for name. With name and wordlist, assigns wordlist as
the alias of name. wordlist is command and filename substi-
tuted. name may not be ‘alias’ or ‘unalias’. See also the
unalias builtin command.
alloc Shows the amount of dynamic memory acquired, broken down into
used and free memory. With an argument shows the number of
free and used blocks in each size category. The categories
start at size 8 and double at each step. This command’s output
may vary across system types, because systems other than the
VAX may use a different memory allocator.
bg [%job ...]
Puts the specified jobs (or, without arguments, the current
job) into the background, continuing each if it is stopped.
job may be a number, a string, ‘’, ‘%’, ‘+’ or ‘-’ as described
under Jobs.
bindkey [-l|-d|-e|-v|-u] (+)
bindkey [-a] [-b] [-k] [-r] [--] key (+)
bindkey [-a] [-b] [-k] [-c|-s] [--] key command (+)
Without options, the first form lists all bound keys and the
editor command to which each is bound, the second form lists
the editor command to which key is bound and the third form
binds the editor command command to key. Options include:
-l Lists all editor commands and a short description of each.
-d Binds all keys to the standard bindings for the default
editor.
-e Binds all keys to the standard GNU Emacs-like bindings.
-v Binds all keys to the standard vi(1)-like bindings.
-a Lists or changes key-bindings in the alternative key map.
This is the key map used in vi command mode.
-b key is interpreted as a control character written ^charac-
ter (e.g., ‘^A’) or C-character (e.g., ‘C-A’), a meta char-
acter written M-character (e.g., ‘M-A’), a function key
written F-string (e.g., ‘F-string’), or an extended prefix
key written X-character (e.g., ‘X-A’).
-k key is interpreted as a symbolic arrow key name, which may
be one of ‘down’, ‘up’, ‘left’ or ‘right’.
-r Removes key’s binding. Be careful: ‘bindkey -r’ does not
bind key to self-insert-command (q.v.), it unbinds key com-
pletely.
-c command is interpreted as a builtin or external command
instead of an editor command.
-s command is taken as a literal string and treated as termi-
nal input when key is typed. Bound keys in command are
themselves reinterpreted, and this continues for ten levels
of interpretation.
-- Forces a break from option processing, so the next word is
taken as key even if it begins with ’-’.
-u (or any invalid option)
Prints a usage message.
key may be a single character or a string. If a command is
bound to a string, the first character of the string is bound
to sequence-lead-in and the entire string is bound to the com-
mand.
Control characters in key can be literal (they can be typed by
preceding them with the editor command quoted-insert, normally
bound to ‘^V’) or written caret-character style, e.g., ‘^A’.
Delete is written ‘^?’ (caret-question mark). key and command
can contain backslashed escape sequences (in the style of Sys-
tem V echo(1)) as follows:
\a Bell
\b Backspace
\e Escape
\f Form feed
\n Newline
\r Carriage return
\t Horizontal tab
\v Vertical tab
\nnn The ASCII character corresponding to the octal num-
ber nnn
‘\’ nullifies the special meaning of the following character,
if it has any, notably ‘\’ and ‘^’.
bs2cmd bs2000-command (+)
Passes bs2000-command to the BS2000 command interpreter for
execution. Only non-interactive commands can be executed, and
it is not possible to execute any command that would overlay
the image of the current process, like /EXECUTE or /CALL-PROCE-
DURE. (BS2000 only)
break Causes execution to resume after the end of the nearest enclos-
ing foreach or while. The remaining commands on the current
line are executed. Multi-level breaks are thus possible by
writing them all on one line.
breaksw Causes a break from a switch, resuming after the endsw.
builtins (+)
Prints the names of all builtin commands.
bye (+) A synonym for the logout builtin command. Available only if
the shell was so compiled; see the version shell variable.
case label:
A label in a switch statement as discussed below.
cd [-p] [-l] [-n|-v] [name]
If a directory name is given, changes the shell’s working
directory to name. If not, changes to home. If name is ‘-’ it
is interpreted as the previous working directory (see Other
substitutions). (+) If name is not a subdirectory of the cur-
rent directory (and does not begin with ‘/’, ‘./’ or ‘../’),
each component of the variable cdpath is checked to see if it
has a subdirectory name. Finally, if all else fails but name
is a shell variable whose value begins with ‘/’, then this is
tried to see if it is a directory.
With -p, prints the final directory stack, just like dirs. The
-l, -n and -v flags have the same effect on cd as on dirs, and
they imply -p. (+)
See also the implicitcd shell variable.
chdir A synonym for the cd builtin command.
complete [command [word/pattern/list[:select]/[[suffix]/] ...]] (+)
Without arguments, lists all completions. With command, lists
completions for command. With command and word etc., defines
completions.
command may be a full command name or a glob-pattern (see File-
name substitution). It can begin with ‘-’ to indicate that
completion should be used only when command is ambiguous.
word specifies which word relative to the current word is to be
completed, and may be one of the following:
c Current-word completion. pattern is a glob-pattern
which must match the beginning of the current word on
the command line. pattern is ignored when completing
the current word.
C Like c, but includes pattern when completing the cur-
rent word.
n Next-word completion. pattern is a glob-pattern which
must match the beginning of the previous word on the
command line.
N Like n, but must match the beginning of the word two
before the current word.
p Position-dependent completion. pattern is a numeric
range, with the same syntax used to index shell vari-
ables, which must include the current word.
list, the list of possible completions, may be one of the fol-
lowing:
a Aliases
b Bindings (editor commands)
c Commands (builtin or external commands)
C External commands which begin with the supplied
path prefix
d Directories
D Directories which begin with the supplied path pre-
fix
e Environment variables
f Filenames
F Filenames which begin with the supplied path prefix
g Groupnames
j Jobs
l Limits
n Nothing
s Shell variables
S Signals
t Plain (‘‘text’’) files
T Plain (‘‘text’’) files which begin with the sup-
plied path prefix
v Any variables
u Usernames
x Like n, but prints select when list-choices is
used.
X Completions
$var Words from the variable var
(...) Words from the given list
‘...‘ Words from the output of command
select is an optional glob-pattern. If given, words from only
list that match select are considered and the fignore shell
variable is ignored. The last three types of completion may
not have a select pattern, and x uses select as an explanatory
message when the list-choices editor command is used.
suffix is a single character to be appended to a successful
completion. If null, no character is appended. If omitted (in
which case the fourth delimiter can also be omitted), a slash
is appended to directories and a space to other words.
command invoked from ‘...‘ version has additional environment
variable set, the variable name is COMMAND_LINE and contains
(as its name indicates) contents of the current (already typed
in) command line. One can examine and use contents of the
COMMAND_LINE variable in her custom script to build more
sophisticated completions (see completion for svn(1) included
in this package).
Now for some examples. Some commands take only directories as
arguments, so there’s no point completing plain files.
> complete cd ’p/1/d/’
completes only the first word following ‘cd’ (‘p/1’) with a
directory. p-type completion can also be used to narrow down
command completion:
> co[^D]
complete compress
> complete -co* ’p/0/(compress)/’
> co[^D]
> compress
This completion completes commands (words in position 0, ‘p/0’)
which begin with ‘co’ (thus matching ‘co*’) to ‘compress’ (the
only word in the list). The leading ‘-’ indicates that this
completion is to be used with only ambiguous commands.
> complete find ’n/-user/u/’
is an example of n-type completion. Any word following ‘find’
and immediately following ‘-user’ is completed from the list of
users.
> complete cc ’c/-I/d/’
demonstrates c-type completion. Any word following ‘cc’ and
beginning with ‘-I’ is completed as a directory. ‘-I’ is not
taken as part of the directory because we used lowercase c.
Different lists are useful with different commands.
> complete alias ’p/1/a/’
> complete man ’p/*/c/’
> complete set ’p/1/s/’
> complete true ’p/1/x:Truth has no options./’
These complete words following ‘alias’ with aliases, ‘man’ with
commands, and ‘set’ with shell variables. ‘true’ doesn’t have
any options, so x does nothing when completion is attempted and
prints ‘Truth has no options.’ when completion choices are
listed.
Note that the man example, and several other examples below,
could just as well have used ’c/*’ or ’n/*’ as ’p/*’.
Words can be completed from a variable evaluated at completion
time,
> complete ftp ’p/1/$hostnames/’
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu
> ftp [^C]
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu
uunet.uu.net)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net
or from a command run at completion time:
> complete kill ’p/*/‘ps | awk \{print\ \$1\}‘/’
> kill -9 [^D]
23113 23377 23380 23406 23429 23529 23530 PID
Note that the complete command does not itself quote its argu-
ments, so the braces, space and ‘$’ in ‘{print $1}’ must be
quoted explicitly.
One command can have multiple completions:
> complete dbx ’p/2/(core)/’ ’p/*/c/’
completes the second argument to ‘dbx’ with the word ‘core’ and
all other arguments with commands. Note that the positional
completion is specified before the next-word completion.
Because completions are evaluated from left to right, if the
next-word completion were specified first it would always match
and the positional completion would never be executed. This is
a common mistake when defining a completion.
The select pattern is useful when a command takes files with
only particular forms as arguments. For example,
> complete cc ’p/*/f:*.[cao]/’
completes ‘cc’ arguments to files ending in only ‘.c’, ‘.a’, or
‘.o’. select can also exclude files, using negation of a glob-
pattern as described under Filename substitution. One might
use
> complete rm ’p/*/f:^*.{c,h,cc,C,tex,1,man,l,y}/’
to exclude precious source code from ‘rm’ completion. Of
course, one could still type excluded names manually or over-
ride the completion mechanism using the complete-word-raw or
list-choices-raw editor commands (q.v.).
The ‘C’, ‘D’, ‘F’ and ‘T’ lists are like ‘c’, ‘d’, ‘f’ and ‘t’
respectively, but they use the select argument in a different
way: to restrict completion to files beginning with a particu-
lar path prefix. For example, the Elm mail program uses ‘=’ as
an abbreviation for one’s mail directory. One might use
> complete elm c@=@F:$HOME/Mail/@
to complete ‘elm -f =’ as if it were ‘elm -f ~/Mail/’. Note
that we used ‘@’ instead of ‘/’ to avoid confusion with the
select argument, and we used ‘$HOME’ instead of ‘~’ because
home directory substitution works at only the beginning of a
word.
suffix is used to add a nonstandard suffix (not space or ‘/’
for directories) to completed words.
> complete finger ’c/*@/$hostnames/’ ’p/1/u/@’
completes arguments to ‘finger’ from the list of users, appends
an ‘@’, and then completes after the ‘@’ from the ‘hostnames’
variable. Note again the order in which the completions are
specified.
Finally, here’s a complex example for inspiration:
> complete find \
’n/-name/f/’ ’n/-newer/f/’ ’n/-{,n}cpio/f/’ \
´n/-exec/c/’ ’n/-ok/c/’ ’n/-user/u/’ \
’n/-group/g/’ ’n/-fstype/(nfs 4.2)/’ \
’n/-type/(b c d f l p s)/’ \
´c/-/(name newer cpio ncpio exec ok user \
group fstype type atime ctime depth inum \
ls mtime nogroup nouser perm print prune \
size xdev)/’ \
’p/*/d/’
This completes words following ‘-name’, ‘-newer’, ‘-cpio’ or
‘ncpio’ (note the pattern which matches both) to files, words
following ‘-exec’ or ‘-ok’ to commands, words following ‘user’
and ‘group’ to users and groups respectively and words follow-
ing ‘-fstype’ or ‘-type’ to members of the given lists. It
also completes the switches themselves from the given list
(note the use of c-type completion) and completes anything not
otherwise completed to a directory. Whew.
Remember that programmed completions are ignored if the word
being completed is a tilde substitution (beginning with ‘~’) or
a variable (beginning with ‘$’). complete is an experimental
feature, and the syntax may change in future versions of the
shell. See also the uncomplete builtin command.
continue
Continues execution of the nearest enclosing while or foreach.
The rest of the commands on the current line are executed.
default:
Labels the default case in a switch statement. It should come
after all case labels.
dirs [-l] [-n|-v]
dirs -S|-L [filename] (+)
dirs -c (+)
The first form prints the directory stack. The top of the
stack is at the left and the first directory in the stack is
the current directory. With -l, ‘~’ or ‘~name’ in the output
is expanded explicitly to home or the pathname of the home
directory for user name. (+) With -n, entries are wrapped
before they reach the edge of the screen. (+) With -v, entries
are printed one per line, preceded by their stack positions.
(+) If more than one of -n or -v is given, -v takes precedence.
-p is accepted but does nothing.
With -S, the second form saves the directory stack to filename
as a series of cd and pushd commands. With -L, the shell
sources filename, which is presumably a directory stack file
saved by the -S option or the savedirs mechanism. In either
case, dirsfile is used if filename is not given and ~/.cshdirs
is used if dirsfile is unset.
Note that login shells do the equivalent of ‘dirs -L’ on
startup and, if savedirs is set, ‘dirs -S’ before exiting.
Because only ~/.tcshrc is normally sourced before ~/.cshdirs,
dirsfile should be set in ~/.tcshrc rather than ~/.login.
The last form clears the directory stack.
echo [-n] word ...
Writes each word to the shell’s standard output, separated by
spaces and terminated with a newline. The echo_style shell
variable may be set to emulate (or not) the flags and escape
sequences of the BSD and/or System V versions of echo; see
echo(1).
echotc [-sv] arg ... (+)
Exercises the terminal capabilities (see termcap(5)) in args.
For example, ’echotc home’ sends the cursor to the home posi-
tion, ’echotc cm 3 10’ sends it to column 3 and row 10, and
’echotc ts 0; echo "This is a test."; echotc fs’ prints "This
is a test." in the status line.
If arg is ’baud’, ’cols’, ’lines’, ’meta’ or ’tabs’, prints the
value of that capability ("yes" or "no" indicating that the
terminal does or does not have that capability). One might use
this to make the output from a shell script less verbose on
slow terminals, or limit command output to the number of lines
on the screen:
> set history=‘echotc lines‘
> @ history--
Termcap strings may contain wildcards which will not echo cor-
rectly. One should use double quotes when setting a shell
variable to a terminal capability string, as in the following
example that places the date in the status line:
> set tosl="‘echotc ts 0‘"
> set frsl="‘echotc fs‘"
> echo -n "$tosl";date; echo -n "$frsl"
With -s, nonexistent capabilities return the empty string
rather than causing an error. With -v, messages are verbose.
else
end
endif
endsw See the description of the foreach, if, switch, and while
statements below.
eval arg ...
Treats the arguments as input to the shell and executes the
resulting command(s) in the context of the current shell. This
is usually used to execute commands generated as the result of
command or variable substitution, because parsing occurs before
these substitutions. See tset(1) for a sample use of eval.
exec command
Executes the specified command in place of the current shell.
exit [expr]
The shell exits either with the value of the specified expr (an
expression, as described under Expressions) or, without expr,
with the value 0.
fg [%job ...]
Brings the specified jobs (or, without arguments, the current
job) into the foreground, continuing each if it is stopped.
job may be a number, a string, ‘’, ‘%’, ‘+’ or ‘-’ as described
under Jobs. See also the run-fg-editor editor command.
filetest -op file ... (+)
Applies op (which is a file inquiry operator as described under
File inquiry operators) to each file and returns the results as
a space-separated list.
foreach name (wordlist)
...
end Successively sets the variable name to each member of wordlist
and executes the sequence of commands between this command and
the matching end. (Both foreach and end must appear alone on
separate lines.) The builtin command continue may be used to
continue the loop prematurely and the builtin command break to
terminate it prematurely. When this command is read from the
terminal, the loop is read once prompting with ‘foreach? ’ (or
prompt2) before any statements in the loop are executed. If
you make a mistake typing in a loop at the terminal you can rub
it out.
getspath (+)
Prints the system execution path. (TCF only)
getxvers (+)
Prints the experimental version prefix. (TCF only)
glob wordlist
Like echo, but the ‘-n’ parameter is not recognized and words
are delimited by null characters in the output. Useful for
programs which wish to use the shell to filename expand a list
of words.
goto word
word is filename and command-substituted to yield a string of
the form ‘label’. The shell rewinds its input as much as pos-
sible, searches for a line of the form ‘label:’, possibly pre-
ceded by blanks or tabs, and continues execution after that
line.
hashstat
Prints a statistics line indicating how effective the internal
hash table has been at locating commands (and avoiding exec’s).
An exec is attempted for each component of the path where the
hash function indicates a possible hit, and in each component
which does not begin with a ‘/’.
On machines without vfork(2), prints only the number and size
of hash buckets.
history [-hTr] [n]
history -S|-L|-M [filename] (+)
history -c (+)
The first form prints the history event list. If n is given
only the n most recent events are printed or saved. With -h,
the history list is printed without leading numbers. If -T is
specified, timestamps are printed also in comment form. (This
can be used to produce files suitable for loading with ’history
-L’ or ’source -h’.) With -r, the order of printing is most
recent first rather than oldest first.
With -S, the second form saves the history list to filename.
If the first word of the savehist shell variable is set to a
number, at most that many lines are saved. If the second word
of savehist is set to ‘merge’, the history list is merged with
the existing history file instead of replacing it (if there is
one) and sorted by time stamp. (+) Merging is intended for an
environment like the X Window System with several shells in
simultaneous use. Currently it succeeds only when the shells
quit nicely one after another.
With -L, the shell appends filename, which is presumably a his-
tory list saved by the -S option or the savehist mechanism, to
the history list. -M is like -L, but the contents of filename
are merged into the history list and sorted by timestamp. In
either case, histfile is used if filename is not given and
~/.history is used if histfile is unset. ‘history -L’ is
exactly like ’source -h’ except that it does not require a
filename.
Note that login shells do the equivalent of ‘history -L’ on
startup and, if savehist is set, ‘history -S’ before exiting.
Because only ~/.tcshrc is normally sourced before ~/.history,
histfile should be set in ~/.tcshrc rather than ~/.login.
If histlit is set, the first and second forms print and save
the literal (unexpanded) form of the history list.
The last form clears the history list.
hup [command] (+)
With command, runs command such that it will exit on a hangup
signal and arranges for the shell to send it a hangup signal
when the shell exits. Note that commands may set their own
response to hangups, overriding hup. Without an argument
(allowed in only a shell script), causes the shell to exit on a
hangup for the remainder of the script. See also Signal han-
dling and the nohup builtin command.
if (expr) command
If expr (an expression, as described under Expressions) evalu-
ates true, then command is executed. Variable substitution on
command happens early, at the same time it does for the rest of
the if command. command must be a simple command, not an
alias, a pipeline, a command list or a parenthesized command
list, but it may have arguments. Input/output redirection
occurs even if expr is false and command is thus not executed;
this is a bug.
if (expr) then
...
else if (expr2) then
...
else
...
endif If the specified expr is true then the commands to the first
else are executed; otherwise if expr2 is true then the commands
to the second else are executed, etc. Any number of else-if
pairs are possible; only one endif is needed. The else part is
likewise optional. (The words else and endif must appear at
the beginning of input lines; the if must appear alone on its
input line or after an else.)
inlib shared-library ... (+)
Adds each shared-library to the current environment. There is
no way to remove a shared library. (Domain/OS only)
jobs [-l]
Lists the active jobs. With -l, lists process IDs in addition
to the normal information. On TCF systems, prints the site on
which each job is executing.
kill [-s signal] %job|pid ...
kill -l The first and second forms sends the specified signal (or, if
none is given, the TERM (terminate) signal) to the specified
jobs or processes. job may be a number, a string, ‘’, ‘%’, ‘+’
or ‘-’ as described under Jobs. Signals are either given by
number or by name (as given in /usr/include/signal.h, stripped
of the prefix ‘SIG’). There is no default job; saying just
‘kill’ does not send a signal to the current job. If the sig-
nal being sent is TERM (terminate) or HUP (hangup), then the
job or process is sent a CONT (continue) signal as well. The
third form lists the signal names.
limit [-h] [resource [maximum-use]]
Limits the consumption by the current process and each process
it creates to not individually exceed maximum-use on the speci-
fied resource. If no maximum-use is given, then the current
limit is printed; if no resource is given, then all limitations
are given. If the -h flag is given, the hard limits are used
instead of the current limits. The hard limits impose a ceil-
ing on the values of the current limits. Only the super-user
may raise the hard limits, but a user may lower or raise the
current limits within the legal range.
Controllable resources currently include (if supported by the
OS):
cputime
the maximum number of cpu-seconds to be used by each
process
filesize
the largest single file which can be created
datasize
the maximum growth of the data+stack region via sbrk(2)
beyond the end of the program text
stacksize
the maximum size of the automatically-extended stack
region
coredumpsize
the size of the largest core dump that will be created
memoryuse
the maximum amount of physical memory a process may have
allocated to it at a given time (this is not implemented
in the 2.6 kernel. The value is meaningless and changing
this value will have no effect)
heapsize
the maximum amount of memory a process may allocate per
brk() system call
descriptors or openfiles
the maximum number of open files for this process
concurrency
the maximum number of threads for this process
memorylocked
the maximum size which a process may lock into memory
using mlock(2)
maxproc
the maximum number of simultaneous processes for this
user id
sbsize the maximum size of socket buffer usage for this user
swapsize
the maximum amount of swap space reserved or used for
this user
maximum-use may be given as a (floating point or integer) num-
ber followed by a scale factor. For all limits other than
cputime the default scale is ‘k’ or ‘kilobytes’ (1024 bytes); a
scale factor of ‘m’ or ‘megabytes’ may also be used. For
cputime the default scaling is ‘seconds’, while ‘m’ for minutes
or ‘h’ for hours, or a time of the form ‘mm:ss’ giving minutes
and seconds may be used.
For both resource names and scale factors, unambiguous prefixes
of the names suffice.
log (+) Prints the watch shell variable and reports on each user indi-
cated in watch who is logged in, regardless of when they last
logged in. See also watchlog.
login Terminates a login shell, replacing it with an instance of
/bin/login. This is one way to log off, included for compati-
bility with sh(1).
logout Terminates a login shell. Especially useful if ignoreeof is
set.
ls-F [-switch ...] [file ...] (+)
Lists files like ‘ls -F’, but much faster. It identifies each
type of special file in the listing with a special character:
/ Directory
* Executable
# Block device
% Character device
| Named pipe (systems with named pipes only)
= Socket (systems with sockets only)
@ Symbolic link (systems with symbolic links only)
+ Hidden directory (AIX only) or context dependent (HP/UX
only)
: Network special (HP/UX only)
If the listlinks shell variable is set, symbolic links are
identified in more detail (on only systems that have them, of
course):
@ Symbolic link to a non-directory
> Symbolic link to a directory
& Symbolic link to nowhere
listlinks also slows down ls-F and causes partitions holding
files pointed to by symbolic links to be mounted.
If the listflags shell variable is set to ‘x’, ‘a’ or ‘A’, or
any combination thereof (e.g., ‘xA’), they are used as flags to
ls-F, making it act like ‘ls -xF’, ‘ls -Fa’, ‘ls -FA’ or a com-
bination (e.g., ‘ls -FxA’). On machines where ‘ls -C’ is not
the default, ls-F acts like ‘ls -CF’, unless listflags contains
an ‘x’, in which case it acts like ‘ls -xF’. ls-F passes its
arguments to ls(1) if it is given any switches, so ‘alias ls
ls-F’ generally does the right thing.
The ls-F builtin can list files using different colors depend-
ing on the filetype or extension. See the color tcsh variable
and the LS_COLORS environment variable.
migrate [-site] pid|%jobid ... (+)
migrate -site (+)
The first form migrates the process or job to the site speci-
fied or the default site determined by the system path. The
second form is equivalent to ‘migrate -site $$’: it migrates
the current process to the specified site. Migrating the shell
itself can cause unexpected behavior, because the shell does
not like to lose its tty. (TCF only)
newgrp [-] group (+)
Equivalent to ‘exec newgrp’; see newgrp(1). Available only if
the shell was so compiled; see the version shell variable.
nice [+number] [command]
Sets the scheduling priority for the shell to number, or, with-
out number, to 4. With command, runs command at the appropri-
ate priority. The greater the number, the less cpu the process
gets. The super-user may specify negative priority by using
‘nice -number ...’. Command is always executed in a sub-shell,
and the restrictions placed on commands in simple if statements
apply.
nohup [command]
With command, runs command such that it will ignore hangup sig-
nals. Note that commands may set their own response to
hangups, overriding nohup. Without an argument (allowed in
only a shell script), causes the shell to ignore hangups for
the remainder of the script. See also Signal handling and the
hup builtin command.
notify [%job ...]
Causes the shell to notify the user asynchronously when the
status of any of the specified jobs (or, without %job, the cur-
rent job) changes, instead of waiting until the next prompt as
is usual. job may be a number, a string, ‘’, ‘%’, ‘+’ or ‘-’
as described under Jobs. See also the notify shell variable.
onintr [-|label]
Controls the action of the shell on interrupts. Without argu-
ments, restores the default action of the shell on interrupts,
which is to terminate shell scripts or to return to the termi-
nal command input level. With ‘-’, causes all interrupts to be
ignored. With label, causes the shell to execute a ‘goto
label’ when an interrupt is received or a child process termi-
nates because it was interrupted.
onintr is ignored if the shell is running detached and in sys-
tem startup files (see FILES), where interrupts are disabled
anyway.
popd [-p] [-l] [-n|-v] [+n]
Without arguments, pops the directory stack and returns to the
new top directory. With a number ‘+n’, discards the n’th entry
in the stack.
Finally, all forms of popd print the final directory stack,
just like dirs. The pushdsilent shell variable can be set to
prevent this and the -p flag can be given to override pushdsi-
lent. The -l, -n and -v flags have the same effect on popd as
on dirs. (+)
printenv [name] (+)
Prints the names and values of all environment variables or,
with name, the value of the environment variable name.
pushd [-p] [-l] [-n|-v] [name|+n]
Without arguments, exchanges the top two elements of the direc-
tory stack. If pushdtohome is set, pushd without arguments
does ‘pushd ~’, like cd. (+) With name, pushes the current
working directory onto the directory stack and changes to name.
If name is ‘-’ it is interpreted as the previous working direc-
tory (see Filename substitution). (+) If dunique is set, pushd
removes any instances of name from the stack before pushing it
onto the stack. (+) With a number ‘+n’, rotates the nth ele-
ment of the directory stack around to be the top element and
changes to it. If dextract is set, however, ‘pushd +n’
extracts the nth directory, pushes it onto the top of the stack
and changes to it. (+)
Finally, all forms of pushd print the final directory stack,
just like dirs. The pushdsilent shell variable can be set to
prevent this and the -p flag can be given to override pushdsi-
lent. The -l, -n and -v flags have the same effect on pushd as
on dirs. (+)
rehash Causes the internal hash table of the contents of the directo-
ries in the path variable to be recomputed. This is needed if
new commands are added to directories in path while you are
logged in. This should be necessary only if you add commands
to one of your own directories, or if a systems programmer
changes the contents of one of the system directories. Also
flushes the cache of home directories built by tilde expansion.
repeat count command
The specified command, which is subject to the same restric-
tions as the command in the one line if statement above, is
executed count times. I/O redirections occur exactly once,
even if count is 0.
rootnode //nodename (+)
Changes the rootnode to //nodename, so that ‘/’ will be inter-
preted as ‘//nodename’. (Domain/OS only)
sched (+)
sched [+]hh:mm command (+)
sched -n (+)
The first form prints the scheduled-event list. The sched
shell variable may be set to define the format in which the
scheduled-event list is printed. The second form adds command
to the scheduled-event list. For example,
> sched 11:00 echo It\’s eleven o\’clock.
causes the shell to echo ‘It’s eleven o’clock.’ at 11 AM. The
time may be in 12-hour AM/PM format
> sched 5pm set prompt=’[%h] It\’s after 5; go home: >’
or may be relative to the current time:
> sched +2:15 /usr/lib/uucp/uucico -r1 -sother
A relative time specification may not use AM/PM format. The
third form removes item n from the event list:
> sched
1 Wed Apr 4 15:42 /usr/lib/uucp/uucico -r1 -sother
2 Wed Apr 4 17:00 set prompt=[%h] It’s after 5; go
home: >
> sched -2
> sched
1 Wed Apr 4 15:42 /usr/lib/uucp/uucico -r1 -sother
A command in the scheduled-event list is executed just before
the first prompt is printed after the time when the command is
scheduled. It is possible to miss the exact time when the com-
mand is to be run, but an overdue command will execute at the
next prompt. A command which comes due while the shell is
waiting for user input is executed immediately. However, nor-
mal operation of an already-running command will not be inter-
rupted so that a scheduled-event list element may be run.
This mechanism is similar to, but not the same as, the at(1)
command on some Unix systems. Its major disadvantage is that
it may not run a command at exactly the specified time. Its
major advantage is that because sched runs directly from the
shell, it has access to shell variables and other structures.
This provides a mechanism for changing one’s working environ-
ment based on the time of day.
set
set name ...
set name=word ...
set [-r] [-f|-l] name=(wordlist) ... (+)
set name[index]=word ...
set -r (+)
set -r name ... (+)
set -r name=word ... (+)
The first form of the command prints the value of all shell
variables. Variables which contain more than a single word
print as a parenthesized word list. The second form sets name
to the null string. The third form sets name to the single
word. The fourth form sets name to the list of words in
wordlist. In all cases the value is command and filename
expanded. If -r is specified, the value is set read-only. If
-f or -l are specified, set only unique words keeping their
order. -f prefers the first occurrence of a word, and -l the
last. The fifth form sets the index’th component of name to
word; this component must already exist. The sixth form lists
only the names of all shell variables that are read-only. The
seventh form makes name read-only, whether or not it has a
value. The eighth form is the same as the third form, but make
name read-only at the same time.
These arguments can be repeated to set and/or make read-only
multiple variables in a single set command. Note, however,
that variable expansion happens for all arguments before any
setting occurs. Note also that ‘=’ can be adjacent to both
name and word or separated from both by whitespace, but cannot
be adjacent to only one or the other. See also the unset
builtin command.
setenv [name [value]]
Without arguments, prints the names and values of all environ-
ment variables. Given name, sets the environment variable name
to value or, without value, to the null string.
setpath path (+)
Equivalent to setpath(1). (Mach only)
setspath LOCAL|site|cpu ... (+)
Sets the system execution path. (TCF only)
settc cap value (+)
Tells the shell to believe that the terminal capability cap (as
defined in termcap(5)) has the value value. No sanity checking
is done. Concept terminal users may have to ‘settc xn no’ to
get proper wrapping at the rightmost column.
setty [-d|-q|-x] [-a] [[+|-]mode] (+)
Controls which tty modes (see Terminal management) the shell
does not allow to change. -d, -q or -x tells setty to act on
the ‘edit’, ‘quote’ or ‘execute’ set of tty modes respectively;
without -d, -q or -x, ‘execute’ is used.
Without other arguments, setty lists the modes in the chosen
set which are fixed on (‘+mode’) or off (‘-mode’). The avail-
able modes, and thus the display, vary from system to system.
With -a, lists all tty modes in the chosen set whether or not
they are fixed. With +mode, -mode or mode, fixes mode on or
off or removes control from mode in the chosen set. For exam-
ple, ‘setty +echok echoe’ fixes ‘echok’ mode on and allows com-
mands to turn ‘echoe’ mode on or off, both when the shell is
executing commands.
setxvers [string] (+)
Set the experimental version prefix to string, or removes it if
string is omitted. (TCF only)
shift [variable]
Without arguments, discards argv[1] and shifts the members of
argv to the left. It is an error for argv not to be set or to
have less than one word as value. With variable, performs the
same function on variable.
source [-h] name [args ...]
The shell reads and executes commands from name. The commands
are not placed on the history list. If any args are given,
they are placed in argv. (+) source commands may be nested; if
they are nested too deeply the shell may run out of file
descriptors. An error in a source at any level terminates all
nested source commands. With -h, commands are placed on the
history list instead of being executed, much like ‘history -L’.
stop %job|pid ...
Stops the specified jobs or processes which are executing in
the background. job may be a number, a string, ‘’, ‘%’, ‘+’ or
‘-’ as described under Jobs. There is no default job; saying
just ‘stop’ does not stop the current job.
suspend Causes the shell to stop in its tracks, much as if it had been
sent a stop signal with ^Z. This is most often used to stop
shells started by su(1).
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw Each case label is successively matched, against the specified
string which is first command and filename expanded. The file
metacharacters ‘*’, ‘?’ and ‘[...]’ may be used in the case
labels, which are variable expanded. If none of the labels
match before a ‘default’ label is found, then the execution
begins after the default label. Each case label and the
default label must appear at the beginning of a line. The com-
mand breaksw causes execution to continue after the endsw.
Otherwise control may fall through case labels and default
labels as in C. If no label matches and there is no default,
execution continues after the endsw.
telltc (+)
Lists the values of all terminal capabilities (see termcap(5)).
termname [terminal type] (+)
Tests if terminal type (or the current value of TERM if no ter-
minal type is given) has an entry in the hosts termcap(5) or
terminfo(5) database. Prints the terminal type to stdout and
returns 0 if an entry is present otherwise returns 1.
time [command]
Executes command (which must be a simple command, not an alias,
a pipeline, a command list or a parenthesized command list) and
prints a time summary as described under the time variable. If
necessary, an extra shell is created to print the time statis-
tic when the command completes. Without command, prints a time
summary for the current shell and its children.
umask [value]
Sets the file creation mask to value, which is given in octal.
Common values for the mask are 002, giving all access to the
group and read and execute access to others, and 022, giving
read and execute access to the group and others. Without
value, prints the current file creation mask.
unalias pattern
Removes all aliases whose names match pattern. ‘unalias *’
thus removes all aliases. It is not an error for nothing to be
unaliased.
uncomplete pattern (+)
Removes all completions whose names match pattern. ‘uncomplete
*’ thus removes all completions. It is not an error for noth-
ing to be uncompleted.
unhash Disables use of the internal hash table to speed location of
executed programs.
universe universe (+)
Sets the universe to universe. (Masscomp/RTU only)
unlimit [-hf] [resource]
Removes the limitation on resource or, if no resource is speci-
fied, all resource limitations. With -h, the corresponding
hard limits are removed. Only the super-user may do this.
Note that unlimit may not exit successful, since most systems
do not allow descriptors to be unlimited. With -f errors are
ignored.
unset pattern
Removes all variables whose names match pattern, unless they
are read-only. ‘unset *’ thus removes all variables unless
they are read-only; this is a bad idea. It is not an error for
nothing to be unset.
unsetenv pattern
Removes all environment variables whose names match pattern.
‘unsetenv *’ thus removes all environment variables; this is a
bad idea. It is not an error for nothing to be unsetenved.
ver [systype [command]] (+)
Without arguments, prints SYSTYPE. With systype, sets SYSTYPE
to systype. With systype and command, executes command under
systype. systype may be ‘bsd4.3’ or ‘sys5.3’. (Domain/OS
only)
wait The shell waits for all background jobs. If the shell is
interactive, an interrupt will disrupt the wait and cause the
shell to print the names and job numbers of all outstanding
jobs.
warp universe (+)
Sets the universe to universe. (Convex/OS only)
watchlog (+)
An alternate name for the log builtin command (q.v.). Avail-
able only if the shell was so compiled; see the version shell
variable.
where command (+)
Reports all known instances of command, including aliases,
builtins and executables in path.
which command (+)
Displays the command that will be executed by the shell after
substitutions, path searching, etc. The builtin command is
just like which(1), but it correctly reports tcsh aliases and
builtins and is 10 to 100 times faster. See also the which-
command editor command.
while (expr)
...
end Executes the commands between the while and the matching end
while expr (an expression, as described under Expressions)
evaluates non-zero. while and end must appear alone on their
input lines. break and continue may be used to terminate or
continue the loop prematurely. If the input is a terminal, the
user is prompted the first time through the loop as with fore-
ach.
Special aliases (+)
If set, each of these aliases executes automatically at the indicated
time. They are all initially undefined.
beepcmd Runs when the shell wants to ring the terminal bell.
cwdcmd Runs after every change of working directory. For example, if
the user is working on an X window system using xterm(1) and a
re-parenting window manager that supports title bars such as
twm(1) and does
> alias cwdcmd ’echo -n "^[]2;${HOST}:$cwd ^G"’
then the shell will change the title of the running xterm(1) to
be the name of the host, a colon, and the full current working
directory. A fancier way to do that is
> alias cwdcmd ’echo -n
"^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"’
This will put the hostname and working directory on the title
bar but only the hostname in the icon manager menu.
Note that putting a cd, pushd or popd in cwdcmd may cause an
infinite loop. It is the author’s opinion that anyone doing so
will get what they deserve.
jobcmd Runs before each command gets executed, or when the command
changes state. This is similar to postcmd, but it does not
print builtins.
> alias jobcmd ’echo -n "^[]2\;\!#:q^G"’
then executing vi foo.c will put the command string in the
xterm title bar.
helpcommand
Invoked by the run-help editor command. The command name for
which help is sought is passed as sole argument. For example,
if one does
> alias helpcommand ’\!:1 --help’
then the help display of the command itself will be invoked,
using the GNU help calling convention. Currently there is no
easy way to account for various calling conventions (e.g., the
customary Unix ‘-h’), except by using a table of many commands.
periodic
Runs every tperiod minutes. This provides a convenient means
for checking on common but infrequent changes such as new mail.
For example, if one does
> set tperiod = 30
> alias periodic checknews
then the checknews(1) program runs every 30 minutes. If peri-
odic is set but tperiod is unset or set to 0, periodic behaves
like precmd.
precmd Runs just before each prompt is printed. For example, if one
does
> alias precmd date
then date(1) runs just before the shell prompts for each com-
mand. There are no limits on what precmd can be set to do, but
discretion should be used.
postcmd Runs before each command gets executed.
> alias postcmd ’echo -n "^[]2\;\!#:q^G"’
then executing vi foo.c will put the command string in the
xterm title bar.
shell Specifies the interpreter for executable scripts which do not
themselves specify an interpreter. The first word should be a
full path name to the desired interpreter (e.g., ‘/bin/csh’ or
‘/usr/local/bin/tcsh’).
Special shell variables
The variables described in this section have special meaning to the
shell.
The shell sets addsuffix, argv, autologout, csubstnonl, command,
echo_style, edit, gid, group, home, loginsh, oid, path, prompt,
prompt2, prompt3, shell, shlvl, tcsh, term, tty, uid, user and version
at startup; they do not change thereafter unless changed by the user.
The shell updates cwd, dirstack, owd and status when necessary, and
sets logout on logout.
The shell synchronizes group, home, path, shlvl, term and user with the
environment variables of the same names: whenever the environment vari-
able changes the shell changes the corresponding shell variable to
match (unless the shell variable is read-only) and vice versa. Note
that although cwd and PWD have identical meanings, they are not syn-
chronized in this manner, and that the shell automatically intercon-
verts the different formats of path and PATH.
addsuffix (+)
If set, filename completion adds ‘/’ to the end of directories
and a space to the end of normal files when they are matched
exactly. Set by default.
afsuser (+)
If set, autologout’s autolock feature uses its value instead of
the local username for kerberos authentication.
ampm (+)
If set, all times are shown in 12-hour AM/PM format.
anyerror (+)
This variable selects what is propagated to the value of the
status variable. For more information see the description of
the status variable below.
argv The arguments to the shell. Positional parameters are taken
from argv, i.e., ‘$1’ is replaced by ‘$argv[1]’, etc. Set by
default, but usually empty in interactive shells.
autocorrect (+)
If set, the spell-word editor command is invoked automatically
before each completion attempt.
autoexpand (+)
If set, the expand-history editor command is invoked automati-
cally before each completion attempt. If this is set to only-
history, then only history will be expanded and a second com-
pletion will expand filenames.
autolist (+)
If set, possibilities are listed after an ambiguous completion.
If set to ‘ambiguous’, possibilities are listed only when no
new characters are added by completion.
autologout (+)
The first word is the number of minutes of inactivity before
automatic logout. The optional second word is the number of
minutes of inactivity before automatic locking. When the shell
automatically logs out, it prints ‘auto-logout’, sets the vari-
able logout to ‘automatic’ and exits. When the shell automati-
cally locks, the user is required to enter his password to con-
tinue working. Five incorrect attempts result in automatic
logout. Set to ‘60’ (automatic logout after 60 minutes, and no
locking) by default in login and superuser shells, but not if
the shell thinks it is running under a window system (i.e., the
DISPLAY environment variable is set), the tty is a pseudo-tty
(pty) or the shell was not so compiled (see the version shell
variable). See also the afsuser and logout shell variables.
backslash_quote (+)
If set, backslashes (‘\’) always quote ‘\’, ‘’’, and ‘"’. This
may make complex quoting tasks easier, but it can cause syntax
errors in csh(1) scripts.
catalog The file name of the message catalog. If set, tcsh use
‘tcsh.${catalog}’ as a message catalog instead of default
‘tcsh’.
cdpath A list of directories in which cd should search for subdirecto-
ries if they aren’t found in the current directory.
color If set, it enables color display for the builtin ls-F and it
passes --color=auto to ls. Alternatively, it can be set to
only ls-F or only ls to enable color to only one command. Set-
ting it to nothing is equivalent to setting it to (ls-F ls).
colorcat
If set, it enables color escape sequence for NLS message files.
And display colorful NLS messages.
command (+)
If set, the command which was passed to the shell with the -c
flag (q.v.).
compat_expr (+)
If set, the shell will evaluate expressions right to left, like
the original csh.
complete (+)
If set to ‘enhance’, completion 1) ignores case and 2) consid-
ers periods, hyphens and underscores (‘.’, ‘-’ and ‘_’) to be
word separators and hyphens and underscores to be equivalent.
If set to ‘igncase’, the completion becomes case insensitive.
continue (+)
If set to a list of commands, the shell will continue the
listed commands, instead of starting a new one.
continue_args (+)
Same as continue, but the shell will execute:
echo ‘pwd‘ $argv > ~/.
コロナウイルスの日ごとの感染者数・死者数をグラフ化してみました。どの国が増加傾向にあり、どの国が終息に向かっているかを視覚化しています。
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa