【Shell 小ネタ】~/.profile 内の export を UPSERT する
概要
~/.profile
内で環境変数が export
されていなければ追記、されていれば値を変更する。
src
grep -q "^export HOGE=" ~/.profile && \ sed -i "s/^export HOGE.*/export HOGE=\"value\"/" ~/.profile || \ echo "export HOGE=\"value\"" >> ~/.profile
おわり。