zshのinfo の読書メモ
これは zsh manual を読みながら書いたメモである。
僕には判りきっている部分とか、必要としない機能とか、意味が判らない場所とかは適当に読み飛しているので注意
1. The Z Shell Manual
1.1 Producing documentation from zsh.texi
html 版マニュアルは http://zsh.sunsite.dk/Doc/ にある
2. Introduction
zsh は、スタンダードなシェルの中では ksh に最も近い。
2.1 Author
zsh をはじめたのは Paul Falstad <pf@zsh.org>.
現在は zsh-workers mailing list <zsh-workers@sunsite.dk> でメンテされていて、コーディネータは Peter Stephenson <pws@zsh.org>. 彼へのコンタクトは coordinator@zsh.org
2.2 Availability
2.3 Mailing Lists
3. Invocation
3.1 Invocation Options
- -c
-
- -i
-
- -s
-
- 標準入力からコマンドを読んで実行
- s フラグの指定がなかったら、第一引数を スクリプトファイルパスと解釈
- -o
-
3.2 Compatibility
sh という名でコールされると、sh の動作をエミュレートし、ksh という名でコールされると ksh をエミュレートする。
3.3 Restricted Shell
r で始まる名前で呼ばれるか -r オプションをつけると 制限モード(restricted mode)で起動
- 制限モード(restricted mode)
- 以下が制限される
- cd でディレクトリ移動
- PATH 等一部パラメータの変更
- '/' を含むコマンド実行
- ハッシュで名前が解決されるコマンド実行
- ファイルへの出力リダイレクト
- 組込みコマンド exec
- job -Z でシェルプロセス上書き
- ARGV0 パラメータ
- 制限モードの解除
制限モードの制限は、スタートアップ処理後に制限がかかる。つまり、スタートアップファイルの処理中は制限がかからない。
4. Files
4.1 Startup/Shutdown Files
- /etc/zshenv(debian的には、/etc/zsh/zshenv)
-
- zsh が最初に読むファイル
- このファイルは必ず読む
- 以下のオプションを unset してスタートアップファイル読み込み停止
- RCS
- 残り全スタートアップファイル読込みを制御
- GLOBAL_RCS
- 残りの /etc 以下のスタートアップファイル読込みを制御
- このファイルはすべての zsh 実行で読みこまれるので、なるべくコンパクトにする
- スタートアップファイル等の読み込み順序
- /etc/zsh/zshenv
- $ZDOTDIR/.zshenv :: 次に読まれるのが、このファイル
- ログインシェルだったら次の二つ
- /etc/zsh/zprofile, $ZDOTDIR/.zprofile
- 対話的に使われるときは
- /etc/zsh/zshrc, $ZDOTDIR/.zshrc
- ログインシェルだったら
- /etc/zsh/zlogin, $ZDOTDIR/.zlogin
- 更にログアウト時に ログインシェルだったら
- $ZDOTDIR/.zlogout, /etc/zlogout
- これらのファイルは、最初の zshenv を省き RCS/GLOBAL_RCS の制御を受ける
- ログアウト時にRCS が unset されていたらヒストリがセーブされない
- /etc/zsh/zshenv
4.2 Files
↓に示した設定ファイうは、実行前に組み込みコマンド zcompile でプリコンパイルすることが出来る。コンパイルしたファイルには .zwc という拡張子が付く
$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
${TMPPREFIX}* (default is /tmp/zsh*)
/etc/zshenv
/etc/zprofile
/etc/zshrc
/etc/zlogin
/etc/zlogout (installation-specific - /etc is the default)
zsh は、コンパイルしたファイルがあると、それがオリジナルより新しい時だけコンパイルしたイメージを使う。
5. Shell Grammar
5.1 Simple Commands & Pipelines
- |&
-
- 普通に書くと 2>&1 |
- つまり 標準出力にくわえ、標準エラーもパイプラインに流す
- これは bash にはない
coproc で子プロセス起動
`>&p' and `<&p' で、子プロセスへの入出力
あるいは `print -p' and `read -p'.とかする
&& は、前のパイプが成功したときのみ(つまり返り値がゼロのとき)次に進む
|| は、逆に 前のパイプが失敗したしたときのみ次に進む
パイプラインは ';', `&', `&|', `&!'か改行のいずれかで終る
5.2 Precommand Modifiers
- -::
- The command is executed with a `-' prepended to its argv[0] string.
- 意味がよく判らん
- noglob
- globbing を抑制する
% noglob ls *
ls: *: そのようなファイルやディレクトリはありませ
- nocorrect
- スペルチェックの抑制
- 他のすべての前置モディファイアより前に置く、最初にパーズされる
- 非対話モードではなにもしない
- exec
- 親シェルからフォークせずに実行
- command
- 組込みじゃない外部コマンドの方を使う
- builtin
- ビルトインの方をつかう
5.3 Complex Commands
if list then list [ elif list then list ] ... [ else list ] fi
- for
-
- for name ... [ in word ... ] term do list done
- names は、複数書いてよい
- n 個の names にすると、n 個ずつlistの値が埋められる
- 値がなくなると空文字列
- term は ';' か改行
- for
-
- for (( [expr1] ; [expr2] ; [expr3] )) do list done
- while list do list done
-
- until list do list done
-
- repeat word do list done
-
- word の評価結果は 非負整数 n にならねばならない
- word の評価結果 n だけ list を繰返し実行
case word in [ [(] pattern [ |
pattern ] ... ) list (;;|;&) ] ... esac |
- リスト 終端が ;& の時は、引き続くリストが ;; か esca に至るまで実行される
select name [ in word ... term ] do list done
- ( list )
- list をサブシェルで実行
- { list }
- リストを実行
- シェル関数
-
- function word ... [ () ] [ term ] { list }
- word ... () [ term ] { list }
- word ... () [ term ] command
- time [ pipeline ]
-
- pipeline 実行時の timing statistics を標準エラーに出力
- exp ]
-
- 条件式を評価して、正(ゼロを返す時)のとき ture を返す
5.4 Alternate Forms For Complex Commands
別の記法。
将来的に廃止される恐れがあるので推奨されない
if list { list } [ elif list { list } ] ... [ else { list } ]
if list sublist
for name ... ( word ... ) sublist
for name ... [ in word ... ] term sublist
for (( [expr1] ; [expr2] ; [expr3] )) sublist
foreach name ... ( word ... ) list end
while list { list }
until list { list }
repeat word sublist
case word { [ [(] pattern [ |
pattern ] ... ) list (;;|;&) ] ... } |
select name [ in word term ] sublist
5.5 Reserved Words
以下の語は、コマンド入力が期待される位置で予約語となっている
do done esac then elif else fi for case if while function repeat time until select coproc nocorrect foreach end ! [[ { }
5.6 Comments
histchars パラメータの三番目のキャラクタ(デフォは #) から改行まではコメントになる
5.7 Aliasing
コマンドポジションのトークンは、まずアライアス定義されていないかチェックする
アライアスの展開は、ヒストリ展開以外の全ての展開に先立ち行なわれる
たとえば foo というアライアスは、\foo と呼ばれると 展開されない
(※ しかし \foo というトークンに対するアライアスを定義することはできる)
5.8 Quoting
キャラクタはバックスラッシュでクォートできる
''
6. Redirection
コマンドの後に & がきて、ジョブコントロールがアクティブじゃなかったら、標準出力は /dev/null にいく。
- <> word
-
- word を読み書き(STDOUT)両用で開く
- ファイルがなければ生成
- <<< word
-
- word にシェルの展開をして、標準入力にする
- here-string と呼ばれる(here-document とは別、注意)
- <& p || >& p
-
The input/output from/to the coprocess is moved to the standard input/output.
- >& word
&> word |
>>& word |
&>> word |
---|
-
6.1 Multios
下のようにして、同時に複数のファイルに書き出すことができる
date >foo >bar
※俺は知らなかったが、これは bash でも出来る
同様に、複数ファイルからの入力も下のように書ける
sort <foo <fubar
※、これは bash では動かない
下のプログラムは、cat file の終了を待たずに、>file{1,2}が始まるので、多分期待した出力にならない。
% cat file >file1 >file2
これを避けるには、シェルの制御のもとで cat file が完了するように、下のように書く。
{ cat file } >file >file2
6.2 Redirections with no command
リダイレクト時に、コマンドを省略すると、下の場合 cat foo という動作をする
% < foo
6.3 Complex Commands
{ TRY-LIST } always { ALWAYS-LIST } ::
まず TRY-LIST が実行され、途中で、エラー、break, continue return があれば、ALWAYS-LIST が実行される
7. Command Execution
コマンドがスラッシュを含まなかったら、1) zsh は、1) まずシェル関数をさがし、2) 次にビルトイン関数を探し、2) $path を探し、それでもなければ、エラーになる。
8. Functions
シェル関数は呼出しプロセスで実行され、環境を共有する。
- ビルトイン関数 functions
- 定義されているシェル関数を出力
- ビルトイン関数 unfunction
- シェル関数定義を undef
8.1 Autoloading Functions
element.tzc
8.2 Special Functions
以下のシェル関数が定義されていれば、特別な意味をもつ
- chpwd
- ディレクトリを移動する時に実行される
- periodic
- PERIOD がセットされていたら、$PERIOD 秒ごとに実行
- precmd
- プロンプトの前の実行
- preexec
-
- コマンドが読み込まれた後、実行の直前に実行される
- 第一引数はユーザの実際の入力
- 二番目の引数が、ちょっと判らん
- 三番目の引数は、実際に実行されるコマンド
- TRAP(NAL)
-
- シグナルNALをキャッチした時に実行する関数
- 第一引数がシグナルの番号
- TRAPDEBUG
- 各コマンドの後に実行
- TRAPEXIT
- シェルもしくはシェル関数が exit する時
- TRAPZERR
-
- コマンドがノンゼロを返したとき
- ただし && とか
の途中にあるときはトラップされない あくまでも、list の最後の値がノンゼロの時 |
---|
9. Jobs & Signals
stty tostop'
- %number
- 番号による JOB参照
- %string
- コマンド開始文字列による JOB参照
- %?string
- 文字列を含むコマンドの参照
- %%
- Current job.
- %-
- Previous job.
9.2 Signals
トバス
10. Arithmetic Evaluation
- let or $(())
- 算術演算
- let
-
- 引数として算術式を取る
- 算術式は個々に評価されるので 2 + 3 とか書くにはクォートが必要
- ((exp)) で、let "exp" と等価
- 算術式中では、10進以外の表現も使える
- 0X or 0x で 16進
- [2-36]#n で、2〜36進数 ex
- つまり 8#16 は、8進の '16'
- 後方互換性のため 816 という書き方も許されている
算術演算式のシンタックスは c に似ている
- 単項演算子 +/- 論理否定 補数 {pre,post}{in,de}crement
-
+ - ! ~ ++ --
- ビット演算
-
<< >> & ^ |
- 加減乗除、剰余、羃
-
+,-,*,/,%, '**'
- 大小比較
-
>,< <=, >=, ==, !=
- 論理和、積
-
&&, ||, ^^(xor)
- 三項演算子
-
? :
- 代入
-
=, +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=, &&=, ||=, ^^=, **=
- カンマ
-
,
数学関数のロード
zmodload zsh/mathfunc
- キャラクタ列
-
##x
##a
##^A
##\M-\C-x
#foo ;パラメータ foo の値の最初のキャラクタ
$#foo
算術演算式のなかでは、名前を(参照用に展開することなく)参照することができる
((val2 = val1 * 2)) # ((val2 = $val1 * 2)) と $ をつけなくてもよい
11. Conditional Expressions
条件式は '[' コマンドと組み合わせて使われる。
- -a file
-
true if file exists.
- -b file
-
true if file exists and is a block special file.
- -c file
-
true if file exists and is a character special file.
- -d file
-
true if file exists and is a directory.
- -e file
-
true if file exists.
- -f file
-
true if file exists and is a regular file.
- -g file
-
true if file exists and has its setgid bit set.
- -h file
-
true if file exists and is a symbolic link.
- -k file
-
true if file exists and has its sticky bit set.
- -n string
-
true if length of string is non-zero.
- -o option
-
true if option named option is on.
- -p file
-
true if file exists and is a FIFO special file (named pipe).
- -r file
-
true if file exists and is readable by current process.
- -s file
-
true if file exists and has size greater than zero.
- -t fd
-
true if file descriptor number fd is open and associated with a terminal device.
- -u file
-
true if file exists and has its setuid bit set.
- -w file
-
true if file exists and is writable by current process.
- -x file
-
true if file exists and is executable by current process.
- -z string
-
true if length of string is zero.
- -L file
-
true if file exists and is a symbolic link.
- -O file
-
true if file exists and is owned by the effective user ID of this process.
- -G file
-
true if file exists and its group matches the effective group ID of this process.
- -S file
-
true if file exists and is a socket.
- -N file
-
true if file exists and its access time is not newer than its modification time.
- file1 -nt file2
-
true if file1 exists and is newer than file2.
- file1 -ot file2
-
true if file1 exists and is older than file2.
- file1 -ef file2
-
true if file1 and file2 exist and refer to the same file.
- string = pattern or string == pattern
- true if string matches pattern.
- The `==' form is the preferred one.
- The `
' form is for backward compatibility and should be considered obsolete.
string ! pattern :: true if string does not match pattern.
- string1 </> string2
-
true if string1 comes before/after string2 based on ASCII value of their characters.
- exp1 -eq exp2
- true if exp1 is numerically equal to exp2.
- exp1 -ne exp2
- true if exp1 is numerically not equal to exp2.
- exp1 -lt/gt exp2
- true if exp1 is numerically less/greater than exp2.
- exp1 -le/ge exp2
- true if exp1 is numerically less/greater than or equal to exp2.
- ( exp )
- true if exp is true.
- ! exp
- true if exp is false.
- exp1 && or
- true if exp1 and/or exp2 are both true.
12. Prompt Expansion
PROMPT_PERCENTオプションがセットされていたら、% で始まるエスケープシーケンスが展開される。
12.0.1 Special characters
- %%
- A `%'.
- %)
- A `)'.
12.0.2 Login information
- %l
-
- The line (tty) the user is logged in on, without `/dev/' prefix.
- If the name starts with `/dev/tty', that prefix is stripped.
- %M
- The full machine hostname.
- %m
- The hostname up to the first `.'.
- An integer may follow the `%' to specify how many components of the hostname are desired.
- With a negative integer, trailing components of the hostname are shown.
- %n
- $USERNAME.
- %y
-
- The line (tty) the user is logged in on, without `/dev/' prefix.
- This does not treat `/dev/tty' names specially.
12.0.3 Shell state
- %#
-
- A `#' if the shell is running with privileges, a `%' if not.
- Equivalent to `%(!.#.%%)'.
- %?
- The return code of the last command executed just before the prompt.
- %d or %/
- Present working directory ($PWD). '
- If an integer follows the `%', it specifies a number of trailing components of $PWD to show;
- zero means the whole path.
- A negative integer specifies leading components, i.e. %-1d specifies the first component.
- %~
-
- As %d and %/, but if $PWD has a named directory as its prefix, that part is replaced by a `~' followed by the name of the directory.
- If it starts with $HOME, that part is replaced by a `~'.
- %h or %!
- Current history event number.
- %i
-
- The line number currently being executed in the script, sourced file, or shell function given by %N.
- This is most useful for debugging as part of $PS4.
- %j
- The number of jobs.
- %L
- The current value of $SHLVL.
- %N
-
- The name of the script, sourced file, or shell function that zsh is currently executing, whichever was started most recently.
- If there is none, this is equivalent to the parameter $0.
- An integer may follow the `%' to specify a number of trailing path components to show;
- zero means the full path.
- A negative integer specifies leading components.
- %c or %. or %C
-
- Trailing component of $PWD.
- An integer may follow the `%' to get more than one component.
- Unless `%C' is used, tilde contraction is performed first.
- These are deprecated as %c and %C are equivalent to %1~ and %1/, respectively.
12.0.4 Date and time
- %D
- The date in yy-mm-dd format.
- %T
- Current time of day, in 24-hour format.
- %t or %@
- Current time of day, in 12-hour, am/pm format.
- %*
- Current time of day in 24-hour format, with seconds.
- %w
- The date in day-dd format.
- %W
- The date in mm/dd/yy format.
- %D{string}
-
- string is formatted using the strftime function. See man page strftime(3)
- Three additional codes are available:
- %f prints the day of the month, like %e but without any preceding space if the day is a single digit,
- %K/%L correspond to %k/%l for the hour of the day (24/12 hour clock) in the same way.
12.0.5 Visual effects
- %B (%b)
- Start (stop) boldface mode.
- %E
- Clear to end of line.
- %U (%u)
- Start (stop) underline mode.
- %S (%s)
- Start (stop) standout mode.
- %{...%}
-
- Include a string as a literal escape sequence.
- The string within the braces should not change the cursor position.
- Brace pairs can nest.
12.0.6 Conditional substrings
- %v
-
- The value of the first element of the psvar array parameter.
- Following the `%' with an integer gives that element of the array.
- Negative integers count from the end of the array.
13. Expansion
シェルの展開は、次の五段階で行なわれる
- History Expansion
- This is performed only in interactive shells.
- Alias Expansion
- Aliases are expanded immediately before the command line is parsed as explained in 5.7 Aliasing.
- Process Substitution
Parameter Expansion
Command Substitution
Arithmetic Expansion
Brace Expansion -
- これら5つについては、左から右の順で展開される。
- 展開後にクォートされていない `\', `'' and `"'は除去される
- Filename Expansion
-
If the SH_FILE_EXPANSION option is set, the order of expansion is modified for compatibility with sh and ksh. In that case filename expansion is performed immediately after alias expansion, preceding the set of five expansions mentioned above.
- Filename Generation
-
This expansion, commonly referred to as globbing, is always done last.
13.1 History Expansion
13.1.1 Overview
!32
!!:n 直前のコマンドの第N引数
!!:$ 直前のコマンドの最後の引数
- ^foo^bar
-
直前のコマンドの foo を baz に置換
^foo^bar^'は、!!:s^foo^bar^ と同義
!" より右で、ヒストリ展開を停止
13.1.2 Event Designators
- !
-
- 直後が、空白、改行、'
', '(' 以外の時ヒストリ展開の開始文字
!! :: 直前のコマンド
!n :: コマンドライン n
!-n :: n 行前のコマンド
!str :: str で始まる直近のコマンド
!?str[?] :: str を含む直近のコマンド
- モディファイアをつけるときは後ろの ? がいる
!# :: 現在コマンドライン
*** 13.1.3 Word Designators
引数を指定する方法
基本形は (イベント指定): 引数指定
0 :: コマンド
n :: n 番目の引数
^/$ :: 最初/最後の引数
% :: 直近の ?str にマッチした語
m-n :: m番目からn番目までの引数
* :: 全ての引数
n* or n- :: n番目から最後まで
*** 13.1.4 Modifiers
引数指定のあとに、コロンに続けて、モディファイアを置くことができる。
これらモディファイアは、ファイル名生成や、パラメータ展開の時もだいたい同じように使える。
h ::
- ディレクトリだけにする
- dirname と同様に働く
r :: 拡張子を除く
e :: 拡張子だけを残す
t ::
- ファイル名からディレクトリ部分と拡張子を除く
- basename のように動作する
p :: コマンドをエコーするけれど実行しない
q :: 置換された語をクォートして、それ以上置換されないようにする
Quote the substituted words, escaping further substitutions.
Q :: クォートを一レベル除去する
l/u :: Convert the words to all lowercase/uppercase.
s/l/r[/]
Substitute r for l as described below. Unless preceded immediately by a g, with no colon between, the substitution is done only for the first string that matches l. For arrays and for filename generation, this applies to each word of the expanded text.
&
Repeat the previous s substitution. Like s, may be preceded immediately by a g. In parameter expansion the & must appear inside braces, and in filename generation it must be quoted with a backslash.
The s/l/r/ substitution works as follows. The left-hand side of substitutions are not regular expressions, but character strings. Any character can be used as the delimiter in place of `/'. A backslash quotes the delimiter character. The character `&', in the right-hand-side r, is replaced by the text from the left-hand-side l. The `&' can be quoted with a backslash. A null l uses the previous string either from the previous l or from the contextual scan string s from `!?s'. You can omit the rightmost delimiter if a newline immediately follows r; the rightmost `?' in a context scan can similarly be omitted. Note the same record of the last l and r is maintained across all forms of expansion.
The following f, F, w and W modifiers work only with parameter expansion and filename generation. They are listed here to provide a single point of reference for all modifiers.
** 13.2 Process Substitution
'<(list)', `>(list)' or `(list)'の格好をしたコマンドライン引数は、プロセス置換の対象となる。
linux では、 前二者は名前付きパイプとして動作する。
13.3 Parameter Expansion
'$' は、パラメータ展開に使われる。
クォートされていないパラメータは、SH_WORD_SPLIT がセットされていないと、自動的には空白で split されない。これは他のシェルとの重要な違いである。
展開
- ${name}
- 変数の値に置換される。
- ${+name}
-
名前がセットされたパラメータだったら 1 そうでなかったらゼロ
- ${name:-word}
-
名前がセットされていて、ノンヌルな値ならば値を返す、
- ${name:=word}
- 名前がセットされていなければ、word をセットする
- or ${name::=word}
-
名前にワードを無条件にセットする
- ${name:?word}
-
- 名前がセットされていてノンヌルならば、値をセットする
- そうでなければ、shell を exit する
- ${name:+word}
-
名前がセットされていてノンヌルならば、word に置換する
- ${name#pattern} ${name##pattern}
-
- パターンが値の頭にマッチしたら、マッチした部分を除いた値に置換
- そうでなかったら、単に値に置換
- # の方は最短マッチ、 ## は最長マッチ
- ${name%pattern} ${name%%pattern}
-
- パターンが値の終りにマッチしたら、マッチした部分を除いた値に置換
- そうでなかったら、単に値に置換
- % の方は最短マッチ、 %% は最長マッチ
- ${name:#pattern}
-
- パターンが名前にマッチしたら空文字列に置換
- そうでなかったら、単に値に置換
- ${name/pattern/repl} ${name//pattern/repl}
-
- 名前のパターンにマッチする部分が repl に置き換えられる
- ${name/pattern/repl} の方が、最初のマッチだけ置換
- ${name//pattern/repl} の方が、すべてんマッチを置換
- ダブルクォート文字列と同じ展開規則が適用されるので下のように書くことができる
${name/$opat/$npat}
- パターンに # や % をつけて、最初や最後のマッチを指定できる
- ${#spec}
-
- spec が変数名だと値の長さ、配列だと配列長
- ^', `
', and `~' を # と組み合わせる時は # より前(左)に置く
${~spec} ::
- spec を評価するときに GLOB_SUBST オプションを on にする
- ~を重ねたら、同オプションを off にする
- 値をパターンとして出力する
*** 13.3.1 Parameter Expansion Flags
パラメータ展開の開き中括弧{の後に開き括弧がくると、閉じ括弧までが、フラグになる。
フラグはどういう順序で書いてもいい。(q%q%q%)よりは (%%qqq)と書く方が判り易いだろう。
% :: すべての %エスケープを展開
※ 個々のパラメータについては省略
*** 13.3.2 Rules
トバス
*** 13.3.3 Examples
${(f)"$(<file)"} は、file の各行を要素とする配列になる。$(<file) なら、ファイル中の
語を要素として格納する配列になるし、"$(<file)" なら、ファイルの内容全体を格納する文字列になる。
** 13.4 Command Substitution
コマンドを、$() もしくはバッククォートで囲んだものは、その標準出力に置換される。
** 13.5 Arithmetic Expansion
exp を算術式として $[exp] と、$((exp)) は、その値に置換される。
算術式は、評価される前に、パラメタ展開、コマンド置換、産出展開を受ける。
** 13.6 Brace Expansion
foo{xx,yy,zz}bar は、fooxxbar,fooyybar,foozzbar に展開される。
{3..5} は、3,4,5 に展開される
{5..3} と降順にも出来る。
** 13.7 Filename Expansion
~ :: $HOME
~+ :: $PWD
~- :: $OLDPWD
~num ::
- ディレクリスタック上のディレクトリに展開
~0 :: ~+ に同じ
~1 :: ~- に同じ
~-01 :: スタックの最後
** 13.8 Filename Generation
クォートされていない `*', `(', `|', `<', `[', or `?' を含むワードは、ファイル名生成パターンとみなされる。
EXTENDED_GLOB オプションがセットされていたら、さらに ^ と # も使える。
ワードは、パターンにマッチするファイル名のソートされたリストに置換される。
マッチするパターンがなかったらエラーメッセージが出る。(これはNULL_GLOB オプションをセットして抑制できる。)
*** 13.8.1 Glob Operators
[!...] :: [^...] に同じ
<[m]-[n]> ::
- n と m の間の任意の数(浮動小数可)にマッチ
- 端点を省略したらオープンエンド
- 両端を省略して <-> なら任意の数とマッチする
- 自然数のマッチなら [...] の方が効率的
(...) :: 囲まれたパターンとマッチ
x~y ::
- パターン X とマッチするけれど y とマッチしないパターン
- EXTENDED_GLOB をセットしないといけない
^pattern ::
- pattern 以外とマッチ
- EXTENDED_GLOB をセットしないといけない
x# ::
- EXTENDED_GLOB をセットしないといけない
- パターンx のゼロ回以上の出現とマッチ、つまり正規表現の x*
x## ::
- EXTENDED_GLOB をセットしないといけない
- パターンx の1回以上の出現とマッチ、つまり正規表現の x+
*** 13.8.2 ksh-like Glob Operators
トバス
*** 13.8.3 Precedence
優先順位は↓の順
<pre class"example">
(highest) `^', `/', `~', `|' (lowest);
13.8.4 Globbing Flags
グロブのフラグを使うには EXTENDED_GLOB のセットが必要
カッコで囲んだグループかパターンの終りに、#X として指定(X は以下のいずれかのフラグ)
- i
- ケースインセンシティブ
- l
- 小文字は大文字にマッチ
- I
- ケースセンシティブ(部分的にケースインセンシティブを解除)
- b
- バックリファレンスをアクティブにする
- B
- バックリファレンスを解除
- m
- 部分ではなく全文字列のマッチ
- M
- m の解除
- anum
-
- あいまいマッチ
- num 個の不一致を許容するマッチ!
- s/e
- s は先頭でマッチ、e は末尾でマッチ
- q
- q 以降閉括弧までの グロブフラグを無視
13.8.5 Approximate Matching
トバス
13.8.6 Recursive Globbing
トバス
13.8.7 Glob Qualifiers
トバス
14. Parameters
14.1 Description
パラメータは、名前と値とアトリビュート数がある
名前は、英数字とアンダースコの列、または単一キャラクタ `', `@', `#', `?', `-', `$', or `!' である。
値は スカラ、文字列、配列、連想配列である
パラメータを宣言し、値をセットするには、ビルトイン関数 typeset を使う
* 14.2 Array Parameters
配列を値として代入するには↓のようにする。
set -A name value ...
name=(value ...
代入することなく、名前を配列だと宣言することもできる
typeset -a name
連想配列は代入する前に↓のように宣言しなくてはならない
typeset -A name
連想配列へのキーバリュー対を格納するには↓のようにする
set -A name key value ...
name=(key value ...
空の連想配列を作るには↓のようにする
set -A name
name=()
14.2.1 Array Subscripts
配列の添字(subscript)は式である。
式は、$((...)) で囲んだときと同様に評価される。
添字は、1 からは始まる。(KSH_ARRAYS オプションをセットすると0 スタートになる)
添字は、中括弧の内側にも外側にも書くことができる。
- ${foo2}' と `$foo2' は同じである
- ただし KSH_ARRAYS オプションをセットすると ${foo2} のみ動作
連想配列の添字は、次のような違いがある
- 算術演算展開(arithmetic expansion )はしない
- しかし算術式としてパーズされる(parsing rules for arithmetic expressions)
- See 14.2.4 Subscript Parsing
- [*] or [@]
- で配列の全要素
- ダブルクォートされていないと両者は同じ意味
ダブルクォートした [*]
- "$foo[*]"
- "$foo1 $foo2 ..."'
- "$foo[@]"
- "$foo1", $foo2 ..."'
連想配列では [*] or [@] で値の列になる。(順序は不定である)
配列 $name が、添字をつけずに $name で参照されると、それは $name[*] で参照されたことになる。(KSH_ARRAYSオプションが有効なら、${name[0]} と等価になる,これは$name が連想配列の時も、キー'0' が定義済みであろうがなかろうが、キー'0'で引くことになる)
添字を [exp1,exp2] のように並べて書くと、exp1 から exp2 までの範囲を指定したことになる。
添字が、負だと、後方から n 番目という意味になる。つまり `$foo[-3]' は後ろから三番目で、 $foo[1,-1] は foo[*] と書くのと同じことになる。
配列でない名前に添字をつけつことも出来る。例えば FOO の値に 'foobar' をセットすると $FOO[2,5] の値は 'ooba' になる
14.2.2 Array Element Assignment
添字付きのパラメータは、代入式の左辺におくこともできる。
name[exp]=value
この場合、すでに name[exp] に値があれば、その位置に value が挿入される。
この場合、すでに name[exp] に値がなければ、name 末尾に value が挿入される。
14.2.3 Subscript Flags
トバス
14.2.4 Subscript Parsing
トバス
14.3 Positional Parameter
位置パラメータ(positional parameters) は、シェルスクリプトやシェル関数のコマンドラインから与えられた引数にアクセスする手段になる。
パラメータ N は N 番目の引数に相当する。
パラメータ *,@,argv は、全ての引数を格納する配列になる
だから、$argv[n] は、$n と同意である。
位置パラメータは 組み込み関数 set や代入によって、書換えたり、新規に生成することが可能である。
位置パラメータ n に、配列を、argv とかは、その分シフトされることになる。(危険、注意)
14.4 Local Parameters
zsh では、変数に入れ子なスコープを設定することができる、つまりローカル変数を使うことができる。
ローカル変数の設定は、typeset でafre integer local readonly などで行なうことができる。
スペシャル変数も、ローカル変数にすることができるが、この場合、初期値が設定されないので、思わぬ誤動作を招くことがある。
14.5 Parameters Set By The Shell
シェルが自動的に設定する変数
- ! <S>
- 直近のバックグラウンドコマンドのプロセスID
The process ID of the last background command invoked.
- # <S>
- 位置パラメータ数
- ARGC <S> <Z>
- # と同じ
- $ <S>
- シェルのプロセスID
- - <S>
- 現在有効なフラグ
- bash にもある
- フラグは、起動時オプションで与えるか、set とか setopt を使って有効/無効にする
* <S> :: 引数のリスト
- argv <S> <Z>
- * に同じ
- @ <S>
- argv[@] と同じ
- ? <S>
- 直近のコマンドの返り値
- 0 <S>
- コマンド名
- FUNCTION_ARGZERO をセットすると、シェル関数の中では、関数名
- status <S> <Z>
- ? に同じ
- pipestatus <S> <Z>
- 直近のパイプライン中のコマンドすべての返り値の配列
- _ (アンダースコア)<S>
- 直近のコマンドの最後の引数
- CPUTYPE
- マシンタイプ (実行時に決定)
- EGID <S>
- 有効グループID
- EUID <S>
- 有効ユーザID
- ERRNO <S>
- 直近のエラーの値
- GID <S>
- シェルプロセスの GID
- HOST
- ホスト名
- LINENO <S>
- 現在スクリプトの行
- LOGNAME
- ログイン名
- MACHTYPE
- マシンタイプ(コンパイル時に決定される)
- OLDPWD
- 直近のワーキングディレクトリ
- OPTARG <S>
- lgetopts された直近のオプション
- OSTYPE
- コンパイル時のOS
- PPID <S>
- 親のPDI
- PWD
- 現在のワーキングディレクトリ
- RANDOM <S>
- 疑似的に 0 から 32767 の間の整数を返す
- RANDOM に数値を代入すると、それをシードにする
- SECONDS <S>
- シェルが呼ばれてからの経過秒
- typeset -F SECONDS とすると、浮動小数で秒を返す
- SHLVL <S>
- シェルが呼ばれる度に1加算される
- signals
- シグナルの名前を格納する配列
- TTY
- シェルが関連ずけられている tty 名
- TTYIDLE <S>
- TTY のアイドルタイム (TTY がなければ -1)
- UID <S>
- シェルプロセスのl UID
- USERNAME <S>
- シェルプロセスのユーザネーム
- VENDOR
- コンパイル時の環境のベンダ名
- ZSH_NAME
- zsh コマンドが呼ばれた時のベースネーム
- ZSH_VERSION
- zsh のバージョン
14.6 Parameters Used By The Shell
シェルが使うパラメータ
path と PATH のように、同じ綴りが、大文字と小文字になっている場合、小文字のパラメータは配列で大文字の方は、各要素がコロンで連結されたスカラー文字列になっている。
片方を unset すると、相方も unset されるので注意
- ARGV0
- ※よく判りません
- BAUD
- 現在の接続のボーレート
- cdpath
(CDPATH )
- cdコマンドのサーチパス
- COLUMNS <S>
- ターミナルの欄数
- DIRSTACKSIZE
- ディレクトリスタックのサイズ上限
- FCEDIT
- ビルトイン関数 fc のデフォールトエディタ
- fignore
(FIGNORE )
- ファイル名補完時に無視するファイルの接尾辞を格納する配列
- fpath
(FPATH ) -
- u アトリビュートのついた関数名の関数のサーチパス
histchars HISTCHARS :: ヒストリ展開等の制御文字三文字
- BASH と同じ
- 第一文字がヒストリ展開文字 デフォは !
- 第二文字が、クイックヒストリ置換(quick history substitution)
- デフォは ^
- 前に入力した文字を置換するのを指示するのに使う
- 三番目の文字は、コメント開示文字
- HISTFILE
- ヒストリをセーブするファイル名
- HISTSIZE
- ヒストリをセーブする量
The maximum number of events stored in the internal history list. If you use the HIST_EXPIRE_DUPS_FIRST option, setting this value larger than the SAVEHIST size will give you the difference as a cushion for saving duplicated history events.
- HOME <S>
- cd コマンドのデフォールト引数
- IFS <S>
- 内部フィールド区切り文字 (Internal Field Separator)
- デフォは space, tab, newline and NUL
- read ビルトインでの単語区切にも使われる。
LANG LC_ :: で始まる変数に、ロケールのカテゴリを決めるために使う
LC_ALL ::LC_ 変数と LANG の値を全て上書き
LINES :: ターミナルの行数
module_path (MODULE_PATH ) :: zmodload がモジュールを探すパス
NULLCMD :: コマンドを省略してリダイレクトした時(たとえば<FILE))に呼ばれるコマンド
path (PATH ) :: コマンドサーチパス
POSTEDIT :: ラインエディタ終了時に出力する文字列
PROMPT |
PROMPT2 |
PROMPT3 ||PROMPT4 :: それぞれ PS1, PS2, PS3 and PS4 に同じ |
prompt :: PS1 に同じ
PS1 :: プライマリなプロンプト文字列
- デフォは `%m%# '
- 表示される前に特殊な展開を受ける (cf 12. Prompt Expansion.)
PS2 :: 行がエスケープされた時なんかのプロンプト
PS3 :: 選択ループのプロンプト
PS4 :: 実行トレースのプロンプト
psvar (PSVAR ) ::
この配列の最初の9 つの値がプロンプトで使われる
READNULLCMD ::
入力リダイレクトでコマンドが省略された時のコマンド
RPROMPT RPS1 :: 右プロンプト
- SINGLELINEZLE オプションがセットされていると動作しない
RPROMPT2 |
PS2 :: 右プロンプト版の PS2 |
- SINGLELINEZLE オプションがセットされていると動作しない
- SAVEHIST
- ヒストリファイルにセーブするイベントの上限
- SPROMPT
- スペルチェック時のプロンプト
- %r は、訂正対象に展開される
- %R は、訂正候補に展開される
TERM :: ターミナルのタイプ
- TMPPREFIX
- セルのテンプファイルを置くパス
WORDCHARS :: ラインエディタで語の要素とみなす非英数字のリスト
- デフォは *?_-.[]~=/&;!#$%^(){}<>
- ZBEEP
- ビジブルベルで表示される文字列
- ZDOTDIR
- シェルスタートアップファイル(.zshrcとか)の場所
15. Options
http://www.gentei.org/~yuuji/rec/pc/intro-zsh.html にある広瀬さんのお薦めオプション
###
# Set shell options
###
setopt auto_menu auto_cd correct auto_name_dirs auto_remove_slash
setopt extended_history hist_ignore_dups hist_ignore_space prompt_subst
setopt pushd_ignore_dups rm_star_silent sun_keyboard_hack
setopt extended_glob list_types no_beep always_last_prompt
setopt cdable_vars sh_word_split auto_param_keys
15.1 Specifying Options
オプション名はケースインセンシティブで、アンダースコアは無視される。
つまり allexprot と A__lleXP_ort は同じと解釈される。
no をつけると意味が逆になる
setopt No_Beeo は、unsetopt beep と同じ意味になる。
この、no による否定は入れ子にできない。つまり no_notify は notify の逆だけれど、tify は No_notify と同意にはならない。
デフォールトのオプションと ksh/sh エミューレート用のオプションは、一文字で 接頭辞 - で有効 + で無効になる。
15.2 Description of Options
以下で、デフォールトでセットされるオプションには マークをつけた。
引数なしで setopt とすると、デフォールトから変更されたオプションが表示される。
ALIASES :: alias を展開する
ALL_EXPORT (-a, ksh: -a) :: 今後定義される名前は自動的にexport する
- ALWAYS_TO_END
- 補完時にカーソルを補完語末尾に移動
- APPEND_HISTORY
- ヒストリリストを上書きではなくアペンドする
- AUTO_CD (-J)
-
- コマンドが実行されず、かつコマンド名とおなじディレクトリがあったら、そこに cd する
- うーん、誤操作を誘発しそう
- AUTO_CONTINUE
-
- disown ビルトインで止めたジョブに CONT シグナルを送って実行継続
AUTO_MENU :: 連続して補完を試みたときに補完メニューを出す
- AUTO_NAME_DIRS
- ※ちょっと判らないのでパス
- AUTO_PARAM_KEYS
- ※ちょっと判らないのでパス
- AUTO_PARAM_SLASH
-
ディレクトリ名が補完された時、その後にスラッシュを補完
- AUTO_PUSHD (-N)
-
ディレクトリ移動した後、前のディレクトリをディレクトリスタックに自動的に push
- AUTO_REMOVE_SLASH
-
補完がスラッシュで終って、つぎの字が、語分割子かスラッシュかコマンドの後にくる文字(; とか & )だったら、補完末尾のスラッシュを取る。
- BEEP (+B)
- Beep on error in ZLE.
- BG_NICE (-6) l
- バックグラウンドジョブを nice する
Run all background jobs at a lower priority. This option is set by default.
- CASE_GLOB
- グロブをケースセンシティブにする。
- CDABLE_VARS
- cd の引数に相当する dir がなくって / で始まってないと ~をつけてみる
- 広瀬リコメンド
- COMPLETE_ALIASES
- ※よくわからん
- CORRECT (-0)
- コマンドのスペルチェックをする
- CORRECT_ALL (-O)
- すべての引数にスペルチェックする
- EMACS
- ZLEがロードされていたら
- bindkey -e 相当の効果
- VI オプションを unset
- このオプションはコンパチビリティのためにあり、bindkey で設定すべきである。
EQUALS :: = ファイル名拡張を行なう
Perform = filename expansion. (See 13.7 Filename Expansion.)
- EXEC (+n, ksh: +n) <D>
- unset すると exec を実行しない
- EXTENDED_GLOB
- #,~,^ をグロブなファイル名生成パターンに使う
- FUNCTION_ARGZERO <C> <Z>
- スクリプト/シェル関数実行時に $0 にスクリプト名/シェル関数名を格納
GLOB (+F, ksh: +f) :: ファイル名生成(See 13.8 Filename Generation.)を行なう
GLOBAL_EXPORT () ::
このオプションをセットすると (declare, float, integer, readonly , typeset に -x オプションが付いたときに、自動的に -g オプションもついたことにする。
GLOBAL_RCS (-d) :: これを有効にすると /etc/zprofile, /etc/zshrc, /etc/zlogin and /etc/zlogout を読み込まない。
- GLOB_COMPLETE
- コンプリーションを試みた位置で、グロブの * を挿入したようなマッチをする。
- GLOB_DOTS (-4)
- カレントディレクトリを意味する最初のドットを要求しない
- HIST_BEEP <D>
- ヒストリをみにいって空だったらビープを鳴らす
- HIST_EXPIRE_DUPS_FIRST
-
- 重複する履歴を先にエクスファイアする。
- HISTSIZE が SAVEHIST より大きな値でないといけない
- ※これはセットしていいかも
- HIST_FIND_NO_DUPS
- zle でヒストリを検索するときに重複するエントリは一度しか表示しない - ※これはセットしていいかも
- HIST_IGNORE_ALL_DUPS
- 重複する履歴を持たない
HIST_IGNORE_DUPS (-h) ::
- 前のコマンドと同じだったらヒストリに入れない
- 広瀬レコメンド
HIST_IGNORE_SPACE (-g) ::
空白ではじまるコマンドをヒストリに保持しない
HIST_NO_FUNCTIONS :: 関数定義をヒストリに残さない
- HIST_NO_STORE
- history コマンドを 履歴から除く
- HIST_REDUCE_BLANKS
- 履歴から冗長な空白を除く
- HIST_SAVE_NO_DUPS
- 履歴セーブ時に冗長なイベントを除く
HUP :: シェルを終了するときに、動いているジョブに HUP を送る
IGNORE_BRACES (-I) :: 中カッコ{}展開を抑制
IGNORE_EOF (-7) :: EOF でexit しない
- INC_APPEND_HISTORY
- シェル終了を待たずに、コマンド入力があった時点で 履歴にアペンドしていく
INTERACTIVE (-i, ksh: -i) :: 対話的に呼んだとき有効になる
INTERACTIVE_COMMENTS (-k) :: 対話モードでもコメントを有効にする
KSH_ARRAYS :: ksh の配列をエミュレートする
- 添字が 1 じゃなくって 0 からはじまる
- 添字も含め中カッコで囲んでやらないといけない。
- $path[2] じゃなくて ${path[2]} と書く
- LIST_PACKED
- 補完候補リストをコンパクトに表示する
- LIST_ROWS_FIRSTl
- 補完候補を水平方向に並べる(デフォは下に並ぶ)
LOGIN (-l, ksh: -l) :: ログインシェルで有効にする
LONG_LIST_JOBS (-R) :: job 表示のデフォをロングフォーマットにする
MARK_DIRS (-8, ksh: -X) :: グロブで生成されたディレクトリ名末尾にスラッシュをつける
MONITOR (-m, ksh: -m) :: ジョブ制御を許可する
MULTIOS :: 名前付きパイプ的に入出力を複数開ける
NOMATCH (+3) :: ファイル名マッチが失敗したときエラーにする
NOTIFY (-5, ksh: -b) :: 入力待ちになるのを待たずに、バックグラウンドジョブのステータスをレポート
- NULL_GLOB (-G)
- グロブのマッチが失敗したら、エラーを出さずに引数リストからパターンを削除
- NOMATCH を上書き
- ※将来的にはセットを考える
- NUMERIC_GLOB_SORT
- グロブで数にマッチするとき、辞書式順じゃなくって数値の順にする
OCTAL_ZEROES :: ゼロではじまる整数を八進として扱う
- デフォになっていないのは、日付とか時間の扱いに難があるから
- OVERSTRIKE
- ラインエディタを上書きモードにする
- PATH_DIRS
- コマンド文字列にスラッシュが含まれていても $path に格納されたパスと連結したコマンドを探す。
つまり、'X11/xinit' というコマンド入力に対して /usr/bin/X11/xinit を探したりする。
PRINT_EXIT_VALUE (-1) :: プログラムがノンゼロで終了したとき、ステータスを出力
PROMPT_PERCENT :: セットするとプロンプト展開で% を特別扱いする See Ch12 Prompt Expansion
- PUSHD_IGNORE_DUPS
- ディレクトリスタックに、同じディレクトリを入れない
- PUSHD_MINUS
- ディレクトリスタックにアクセスするときの +/- の意味を逆にする
- PUSHD_SILENT (-E)
- ディレクトリスタックに push/pop したとき一々出力しない
- PUSHD_TO_HOME (-D)
-
Have pushd with no arguments act like `pushd $HOME'.
- RC_EXPAND_PARAM (-P)
- 中カッコでリスト展開したときの動作を変える
- xx=(a b c) foo${xx}bar -> `fooabar foobbar foocbar' になる
- デフォは`fooa b cbar'.
- ※ bash 的には 前者だから、多分セットすべき
- RC_QUOTES
- シングルクォート文字列中のダブルクォートをシングルクォートに変換
RCS (+f) :: .zshenv, /etc/zprofile, .zprofile, /etc/zshrc, .zshrc, /etc/zlogin, .zlogin, and .zlogout を読み込む。
- unset すると /etc/zshenv 以外は読まない
REC_EXACT (-S) :: 完全マッチを認識する
RM_STAR_SILENT (-H) :: rm * とかするときにクエリしない
- RM_STAR_WAIT
- rm * とかしたときに 実行する前に10秒待つ
- SHORT_LOOPS
- ループの短縮形を許す
SINGLE_LINE_ZLE (-M) :: コマンドラインエディタをマルチラインじゃなくってシングルラインにする
- TRANSIENT_RPROMPT
- 右プロンプトをコマンドラインが受けられたら消す
UNSET (+u, ksh: +u) ::
- unset されたパラメータを、空な値を持つものとして扱う
XTRACE (-x, ksh: -x) :: 実行の度にコマンドを出力する
ZLE (-Z) :: zsh line editor を使う
Use the zsh line editor. Set by default in interactive shells connected to a terminal.
15.3 Option Aliases
いくつかのオプションは別名を持っている。
15.4 Single Letter Options
トバス
16. Shell Builtin Commands
- - simple command
- argv[0] を '-' にする(ログインシェルと同じになる)
- . file [ arg ... ]
- ファイルからコマンドを呼んで、今の環境で実行する
- file が / を含まず、PATH_DIRS オプションがセットされていないと $path からファイルを探す
- カレントディレクトリのファイルを指定するには ./file とかする
- file.zwc があって file より新しければ、そちらを読む
- 引数があれば、位置パラメタ($1 とかね)として扱われる。
: [ arg ... ] :: なにもしないが、引数展開が実行される
alias [ {+|-}gmrsL ] [ name[=value] ... ] ::
- -g
- グローバルアライアス、コマンドじゃないところでも展開
- -s
- サフィックスアライアス
-m
- name はパターンとして解釈される
-L
- スタートアップファイル上の定義用の出力がされる
autoload [ {+|-}UXmt ] [ -wkz ] [ name ... ] ::
※ よくわからん
bg [ job ... ] |
job ... :: 指定したジョブをバックグラウンドに |
- bindkey
- See 17.3 Zle Builtins
- break [n]
- ループからの脱出
builtin name [ args ... ] :: ビルトイン関数 name を実行
command [ -pvV ] command :: 外部コマンド command を実行
continue [ n ] :: ループの次の繰替えしへいく
- 引数 n があると、n-1 のループをブレークして、 n 番目のループにいく?(なんか危険)
- declare
- typeset に同じ
- dirs [ -c ] [ arg ... ]
-
- 引数なしで呼ぶと、ディレクトリスタックの中身を表示
- 引数をつけると、それらをディレクトリスタックに格納
- -c
- ディレクトリスタックをクリア
- -l
- フルパスで表示
- -p
- 一行一ディレクトリで表示
- -v
- スタックに積まれている数を表示
disown [ job ... ] |
job ... &| |
job ... &! :: |
指定したジョブをジョブテーブルから削除
echo [ -neE ] [ arg ... ] ::
- -n
- 行末の改行を行なわない
- -e
- バックスラッシュエスケープ文字の解釈を有効にする
eval [ arg ... ] :: args を評価して、その結果をコマンドとして実行する
- exec cmd
- フォークすることなく自分自身として実行する
- exit [ n ]
- 返り値 n を返してシェルを終了する
- 引数を指定しなかったら、最後に実行されたコマンドの返り値を返す
false [ arg ... ] :: なにもせずに戻り値 1 でシェルを終了
fc [ -e ename ][ -nlrdDfEim ][ old=new ... ][ first [ last ] ] ::
- first last で範囲指定
- first/last の指定はヒストリ番号か、文字列
- 負数 -n なら、現在番号からn 遡る
- 文字列なら、その文字列を含む直近のエントリ
- old=new
- old を new に置換
- l :: 結果をエディタじゃなくって標準出力に出力
- m :: 直後の引数をパターンとしてマッチしたものを出力
- e editor :: editor を起動
- -e オプションがなかったら パラメータ FCEDIT の値が使われる
- -e - でエディタを呼ばない
- r :: コマンドを逆順に並べる
- n :: -l と併用するときリストに番号を表示しない
- i :: タイプタンプ表示
- D :: 経過時間表示
fc -ARWI [ filename ] ::
- -R file
- ファイルから履歴を読む
- -W file
- 履歴をファイルに出力
- -A file
- 履歴をファイルにアペンド
- -I file
- A/W と組み合わせて、冗長を除く
float [ {+|-}EFHghlprtux ] [ name[=value] ... ] :: typeset -E" に同じ
functions [ {+|-}UXmtu ] [ name ... ] :: "typeset -F" に同じ
getln [ -AclneE ] name ... ::
- バッファスタックから一つ読みパラメータ名としてプット
- read -zr に同じ
getopts OptString name [ arg ... ] ::
↓に、例を示す
- optstring が "lLai
- もし引数を取るときは "l:" という具合に パラメタ文字の後にコロンを付ける
- OPTARG
- 直近に処理されたオプション引数の値の値
- OPTIND
- 直近に処理されたオプション引数へのインデクス
- OptString の先頭をコロンにすると、OptString にないオプションが指定されたらname の値を"?"にする
while getopts "lLai" opt; do
if [[ $opt = "?" ]]; then
print -P "%N: unrecognized option: -$OPTARG" >&2
return 1
fi
eval "opt_$opt=${(q)OPTARG:--$opt}"
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
[[ -z $opt_Q ]] && setopt nobareglobqual
[[ -n $opt_M ]] && action=mv
[[ -n $opt_C ]] && action=cp
[[ -n $opt_L ]] && action=ln
[[ -n $opt_p ]] && action=$opt_p
- hash
- トバス
- history
- 'fc -l' に同じ
- integer [ {+|-}Hghilprtux ] [ name[=value] ... ]
-
typeset -i に同じ
- let arg
- arg を算術式として評価
- 最後の式の値がノンゼロならゼロ、ゼロなら1 を返す※注意
- limit
- 各種リソースの上限値を決める
- local [ {+|-}AEFHLRUZahilprtux [n]] [ name[=value] ] ...
-
typeset に同じ
- noglob simple command
- command を グロブしない
- popd
- トバス
- print
- トバス
- printf
- トバス
- pushd
- トバス
- pushln
- トバス
- read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ] [ -u n ] [ name[?prompt] ] [ name ... ]
- トバス
- readonly
- typeset -r に同じ
- rehash
- hash -r に同じ
- return [ n ]
- トバス
- sched [+]hh:mm command ...
- 相対時間でコマンドの実行時間を指定
- see 21.16 The zsh/sched Module
sched [ -item ] :: item をリストから除く
set [ {+|-}options |
{+|-}o [ option_name ] ] ... [ {+|-}A [ name ] ] [ arg ... ] :: |
オプションなどのセット
- setcap
- cap はケイバビリティのcap トバス
- setopt [ {+|-}options
{+|-}o option_name ] [ name ... ] |
-
シェルのオプションをセット
- 引数がないと、セットされたオプションを表示
- -mオプションでパターンを与えることができる
shift [ n ] [ name ... ] :: トバス
source file [ arg ... ] :: . に同じ
- stat
- トバス
- suspend [ -f ]
- シェルをサスペンド
- ログインシェルをサスペンドするときは -f をつける
- SIGCONT でお目覚め
- test
- トバス
- times
- トバス
- trap
- トバス
- true [ arg ... ]
- 返り値 0 でなにもせずにリターン
- ttyctl -fu
- トバス
- type [ -wfpams ] name ...
- whence -v に同じ
- typeset
- トバス
- ulimit [ -SHacdflmnpstv [ limit ] ... ]
-
リソースの制限を解除
umask [ -S ] [ mask ] :: トバス
- unalias
- unhash -a に同じ
- unfunction
- unhash -f に同じ
- unhash [ -adfms ] name ...
- 名前をハッシュから除去
- unlimit [ -hs ] resource ...
- トバス
- unset [ -fmv ] name ...
- パラメタの unset
- unsetopt [ {+|-}options
{+|-}o option_name ] [ name ... ] |
-
setopt の反対
vared [ -Aache ] [ -p prompt ] [ -r rprompt ] name ::
パラメタの値をラインエディタにロードして編集・更新
wait [ job ... ] :: job をウエイト
- 引数がなければカレントプロセスの子プロセスすべてを待つ
whence [ -vcwfpams ] name ... ::
名前が、どのように解釈されるかを指定
where [ -wpms ] name ... :: whence -ca に同じ
which [ -wpams ] name ... :: whence -c. に同じ
- zcompile [ -U ] [ -z | -k ] [ -R | -M ] FILE [ NAME ... ]
- file.zwc を生成
- -U アライアスを展開しない
- -R ファイル読み込み時に、(メモリマップせずに)内容をメモリに展開
- -M コンテンツをメモリマップに読み込むので、プロセス間で共有できる
- -k autoload 時に KSH_AUTOLOAD オプションを付けた時と同様に動作する
- -z autoload 時に KSH_AUTOLOAD オプションを付なかった時と同様に動作する
- zcompile -ca [ -m ] [ -R | -M ] FILE [ NAME ... ]
- c または a オプション付き
- zcompile -t FILE [ NAME ... ]
- t オプションをつけると FILE を調べる
- zformat
- トバス
- zftp
- トバス
- zle
- トバス
- zmodload
- zsh loadable moduleに対する操作を行なう
- 引数なしで呼ぶと、ロード中のモジュールの名を表示
zmodload [ -u -i ] NAMEバイナリモジュールをロード
- ファイル名接尾辞 '.so'
- -i オプションで、重複して読みこまない
- モジュール名は $module_path を捜索する
- -u オプションで unload
- アンロード済みのモジュールをアンロードしてもエラーにならない
- zparseopts
- パラメタ解析するものらしい トバス
- zprof
- プロファイラらしい、トバス
- zpty
- トバス
- zregexparse
- 正規表現がつかえたらすごいが、よくわからん、トバス
- zsocket
- ソケットを直にコントロールできるらしい、トバス
- zstyle
- よくわからんが、連想配列みたいなものの I/F らしい、トバス
- ztcp
- トバス
17. Zsh Line Editor
17.1 Description
zle にはマルチラインモード(デフォ)とシングルラインモードがある。
17.2 Keymaps
17.2.1 Reading Commands
17.3 Zle Builtins
17.4 Widgets
17.5 User-Defined Widgets
トバス
17.6 Standard Widgets
25.5 Exception Handling
catch と throw は、always コンストラクトと組み合わせて使う
典型的な例を以下に示す。
{
# "try" block
# ... nested code here calls "throw MyExcept"
} always {
# "always" block
if catch MyExcept; then
print "Caught exception MyExcept"
elif catch ''; then
print "Caught a shell error. Propagating..."
throw ''
fi
# Other exceptions are not handled but may be caught further
# up the call stack.
}
例外を確実に捕まえるためには、↓のパターンを定石として使える
{
# ... nested code here throws an exception
} always {
if catch *; then
case $CAUGHT in
(MyExcept)
print "Caught my own exception"
;;
(*)
print "Caught some other exception"
;;
esac
fi
}
連絡先:webadmin.itsumi@gmail.com
