shell scriptでのos判定

シェルos, os判定, shell, zsh

広告

今の現状

macでの開発やvagrantのcent osでの開発環境があり、同じ環境ですぐに環境構築ができるように、dotfilesを作りましたが、osやすでにインストールしているかによって、うまく機能していないことが多いです。そこで、osの判定によって、brewを使ってインストールするかなどを記述したdotfilesを作りたいと思いました。

os判定

“uname”コマンドを使うことで、osを判定することができるとのことでしたので、使ってみました。

man uname

  -a      Behave as though all of the options -mnrsv were specified.

     -m      print the machine hardware name.

     -n      print the nodename (the nodename may be a name that the system is known by to a communications network).

     -p      print the machine processor architecture name.

     -r      print the operating system release.

     -s      print the operating system name.

-v      print the operating system version.

条件を分けて、必要なものをインストールしていこうと思います.

  1 if [ "$(uname)" == 'Darwin' ]; then
  2   OS='Mac'
  3 elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then
  4   OS='Linux'  

広告