function isaix { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/.kshrc; }
function islinux { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/.bash_profile; }
OSTYPE="`uname`"; if echo "${OSTYPE}" | grep -iq aix; then isaix; fi; if echo "${OSTYPE}" | grep -iq linux; then islinux; fi
前の行は、最初の20個のファイルとディレクトリをサイズ別にリストする「d」エイリアスを作成します。
質問:この長い行をどのように短くすることができますか? (OSタイプ検知など)
ベストアンサー1
OSTYPE="`uname`"
OSTYPE="${OSTYPE,,}"
case "$OSTYPE" in
*aix*)
target=~/.kshrc
;;
*linux*)
target=~/.bash_profile
;;
esac
if [ -n "$target" ]; then
echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> "$target"
fi