🔎 
  
Live システムマニュアル

コーディングスタイル

コーディングスタイル

この章では Live システムで利用されているコーディングスタイルについて述べます。

互換性

●  Bash シェル固有の書式や記号を使わないでください。例えば配列構造の利用など

●  POSIX のサブセットだけを使ってください - 例えば `foo` よりも $(foo) を使ってください。

●  'sh -n' と 'checkbashisms' によりスクリプトをチェックできます。

●  シェルコードが全て確実に 'set -e' で動作するようにしてください。

インデント

●  常にスペースよりもタブを使います。

改行

●  通常、行は最大で80文字までです。

●  「Linux 式」で改行します:

悪い例:

 if foo; then
         bar
 fi  

良い例:

 if foo
 then
         bar
 fi  

●  関数についても同様です:

悪い例:

 Foo () {
         bar
 }  

良い例:

 Foo ()
 {
         bar
 }  

変数

●  変数は常に大文字です。

●  live-build で利用する変数は先頭を常に LB_ で始めます。

●  live-build 内部の一時変数は \_LB_ で始めます。

●  live-build のローカル変数は \_\_LB_ で始めます。

●  live-config 中のブートパラメータにつながる変数は LIVE_ で始めます。

●  live-config 中の他の変数は全て _ で始めます。

●  変数は大括弧「{}」で囲みます。例えば $FOO ではなく ${FOO} とします。

●  空白文字の可能性を考慮し、常に引用符を使って変数を保護します: ${FOO} ではなく “${FOO}” とします。

●  一貫性を保つため、変数に値を割り当てるときは常に引用符を使います:

悪い例:

 FOO=bar  

良い例:

 FOO="bar"  

●  複数の変数を使うときは表現全体を引用符で囲みます:

悪い例:

 if [ -f "${FOO}"/foo/"${BAR}"/bar ]
 then
         foobar
 fi  

良い例:

 if [ -f "${FOO}/foo/${BAR}/bar" ]
 then
         foobar
 fi  

その他

●  sed を呼び出すときは区切り文字に「|」を使います。例えば「sed -e 's|foo|bar|'

●  比較やテストには test コマンドを使わず、「[」や「]」を使います。例えば「if [ -x /bin/foo ]; ...」を使い、「if test -x /bin/foo; ...」は使いません。

●  test よりも case の方が読みやすく実行速度も早いため、可能な部分ではこちらを使います。

●  ユーザの環境と混ざる可能性を限定するため、関数の名前には大文字を使います。



License: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

The complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-3 file.


≅ SiSU Spine ፨ (object numbering & object search)

(web 1993, object numbering 1997, object search 2002 ...) 2023