Unix-commands-declare
提供:Dev Guides
declare-Unix、Linuxコマンド
NAME
*declare* -変数を宣言し、それらに属性を与えます。
概要
declare [-afFrxi] [-p] [name[=value]]
説明
名前が指定されていない場合、 'declare’は代わりに変数の値を表示します。 -の代わりに+を使用すると、代わりに属性がオフになります。 関数で使用する場合、declareはlocalコマンドと同様に各名前をローカルにします。 typesetコマンドは、Kornシェルとの互換性のために提供されています。ただし、declare builtinコマンドを支持して廃止されました。 無効なオプションが検出されない限り、戻りステータスはゼロです。「-f foo = bar」を使用して関数を定義しようとし、読み取り専用変数に値を割り当てようとし、値を割り当てようとします。複合代入構文を使用せずに配列変数に指定すると、名前の1つが有効なシェル変数名ではありません。読み取り専用変数の読み取り専用ステータスをオフにしようとします。配列変数の配列ステータスをオフにしようとします。または、存在しない関数を「-f」で表示しようとしました。
オプション
Tag | Description |
---|---|
-a | Each name is an array variable. |
-f | Use function names only. |
-F | Inhibit the display of function definitions; only the function name and attributes are printed. (implies -f) |
-i | The variable is to be treated as an integer; arithmetic evaluation is performed when the variable is assigned a value. |
-p | Display the attributes and values of each name. When '-p' is used, additional options are ignored. |
-r | Make names readonly. These names cannot then be assigned values by subsequent assignment statements or unset. |
-x | Mark each name for export to subsequent commands via the environment. |
例
$ declare | grep HOME
HOME=/home/bozo
$ zzy=68
$ declare | grep zzy
zzy=68
$ Colors=([0]="purple" [1]="reddish-orange" [2]="light green")
$ echo ${Colors[@]}
purple reddish-orange light green
bash$ declare | grep Colors
Colors=([0]="purple" [1]="reddish-orange" [2]="light green")
link:/cgi-bin/printpage.cgi [__印刷]