2011年6月7日火曜日

【zsh入門しようと思ったらrootのshパス間違えてログイン出来なくなったのを解決】

zshを周りのイケてるエンジニアの方々が使用されてるので、自分もデフォルトのbashからzshに乗り換えてみます。
環境はubuntu10.10ですぞ。

自分の現在のシェルを確かめるには、

echo $SHELL



less /etc/passwd 

でファイルを見ればおk。


バージョンとダウンロードされいているかの確認はこれ

zsh --version


確認したところで、まずインストールから

sudo apt-get install zsh

zshを自分のデフォルトのシェルとして適用

chsh -s /bin/zsh

でパスワードを要求されるので正しく入力すると、zshが次回ログイン時から使えるようになる。
chshコマンドは、ログインするときに使用するシェルを変更するコマンド。
詳しくは下記
http://www.k-tanaka.net/unix/chsh.html

ここで自分は

chsh -s /sbin/zsh

と入力した上に再ログインするために、一度rootをログアウトしてしまった・・・
再度ログインしようとすると

/sbin/zsh なんてねーよボケ

とエラーメッセージが・・・あれ?rootにならないと上記コマンド打てないんじゃなかったっけ?
sudoもダメorz
もうrootにはなれないのかと諦めかけてたんだけど、最終的に下記で解決した。

/etc/passwd を直接編集

passwdにはデフォルトのシェルのパスも書かれていて、そこを直接編集

sudo vi /etc/passwd

で直った^^ でも、なんでviのsudoはできるんだろう・・・。rootのシェルコマンドを通さないsudoなら可能なのかな?

とりあえず、上記で自分のミスは解決。

まぁこういうミスも勉強になったということで・・・;


再ログインすると、下記のような文章が出現


This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.


You can:


(q)  Quit and do nothing.  The function will be run again next time.


(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.


(1)  Continue to the main menu.




(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).
--- Type one of the keys in parentheses ---


1を押すとzshのいろんな設定ができます。とりあえずhistoryコマンドが使えるようにしといたのと、なんとなく履歴を10000までとっておくことにしました。あとは適宜英語読みながら。(そこが読めないんだけど)

ちなみにデフォルトの.zshrcはこちら


# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/hogehoge/.zshrc'


autoload -Uz compinit
compinit
# End of lines added by compinstall


zshのバージョンはzsh 4.3.10 (i686-pc-linux-gnu)でした。

コマンド+Tabでオプション説明はでるし、Tabでのディレクトリ移動は楽になるしでzsh、良さげです。
というわけで無事zshを快適に使えるようになりました。

今後少しずつカスタマイズなどもやっていこうと思う。

ここにある基本設定はやりました。便利!
http://linuxserver.jp/Linux/ZSH%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB.php

上記を参考に今んとこの自分で書き加えた設定は下記


# My Edit
export LANG=ja_JP.UTF-8
setopt auto_cd
setopt auto_pushd
setopt correct


他の諸々の参考サイトはこちら

http://journal.mycom.co.jp/column/zsh/001/index.html
http://d.hatena.ne.jp/ama-ch/20090109/1231526834
http://gihyo.jp/dev/serial/01/zsh-book/0001
http://d.hatena.ne.jp/kobakey/20101205/1291562308

設定丸々
http://www.cozmixng.org/~kou/linux/zsh
http://homepage1.nifty.com/ablaxas/resources/dot-zshrc

0 件のコメント:

コメントを投稿