docs > shell > Shell_coding_standards

Shell_coding_standards

my bash coding standards

シバン

#!/usr/bin/env bash

インデント

2つ

変数名 & 関数名

引用符

文字列や変数展開には 常にダブルクォート を使用

条件分岐

[[ ... ]]を使う

if [[ "${name}" == "Alice" ]]; then
    echo "Hello, Alice"
elif [[ "${name}" == "Bob" ]]; then
    echo "Hey, Bob"
else
    echo "Who are you?"
fi

ループ

for file in *.txt
do
    echo "$file"
done

コマンド置換

files=$(ls *.txt)

その他