27
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ユーザのログインシェルを調べる

Last updated at Posted at 2013-06-16

Linuxなど

ふつうのUNIX系システムでは /etc/passwd に格納されてるので、これを調べてやればいいです。

% grep $USER /etc/passwd
megurine:x:1000:1000:Megurine Luka,,,:/home/megurine:/usr/bin/zsh
% grep $USER /etc/passwd | cut -d: -f7
/usr/bin/zsh

(AWKならパイプで繋がずに書けるかもしれない)

Mac OS X (v10.5〜)

が、Mac OS Xは「ふつうの」UNIXではないので、この方法では一般ユーザのログインシェルは 取得できません X-D

じゃあどうすればいいか。

OS Xではユーザ情報はOpen Directoryに格納されてるので、これを参照しにいきます。

% dscl localhost -read Local/Default/Users/$USER UserShell
UserShell: /usr/local/bin/zsh
% dscl localhost -read Local/Default/Users/$USER UserShell | cut -d' ' -f2
/usr/local/bin/zsh

ほむ、いい感じですね。やりましたよ。

参考資料

27
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?