質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

zsh

zshは、UNIX系OSのシェルの1つです。 cshやksn系のコマンドライン編集機能も実装されたシェルです。

Q&A

解決済

2回答

2555閲覧

【Mac】bashからzshへの移行方法

roronoazoro

総合スコア113

bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

zsh

zshは、UNIX系OSのシェルの1つです。 cshやksn系のコマンドライン編集機能も実装されたシェルです。

0グッド

0クリップ

投稿2017/11/23 02:02

bashからzshへ移行しようと作業中なのですが、もともと、.bash_profileや.bashrcなどもコピペで行なっていたため、エラーの勝手が分からない状態です。
現在のエラー状態としては、Visual Studio Codeのターミナルにて、source ~/.zshrcとすると下記のようなエラーとなります。

bash

1$:~ ユーザーネーム$ source ~/.zshrc 2bash: autoload: command not found 3bash: /Users/ユーザーネーム/.oh-my-zsh/oh-my-zsh.sh: line 31: syntax error near unexpected token `(' 4bash: /Users/ユーザーネーム/.oh-my-zsh/oh-my-zsh.sh: line 31: `for config_file ($ZSH/lib/*.zsh); do' 5bash: autoload: command not found 6bash: compinit: command not found 7bash: zmodload: command not found 8bash: bindkey: command not found 9bash: bindkey: command not found 10bash: bindkey: command not found 11bash: bindkey: command not found 12bash: setopt: command not found 13bash: setopt: command not found 14bash: bindkey: command not found 15bash: autoload: command not found 16bash: compinit: command not found 17bash: /Users/ユーザーネーム/.zshrc: line 132: syntax error: unexpected end of file 18 19# ~~~~~~~.zshrcファイル ~~~~~~~ 20 21# If you come from bash you might have to change your $PATH. 22# export PATH=$HOME/bin:/usr/local/bin:$PATH 23 24# Path to your oh-my-zsh installation. 25export ZSH=/Users/ユーザーネーム/.oh-my-zsh 26 27# Set name of the theme to load. Optionally, if you set this to "random" 28# it'll load a random theme each time that oh-my-zsh is loaded. 29# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes 30ZSH_THEME="wedisagree" 31 32# Set list of themes to load 33# Setting this variable when ZSH_THEME=random 34# cause zsh load theme from this variable instead of 35# looking in ~/.oh-my-zsh/themes/ 36# An empty array have no effect 37# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) 38 39# Uncomment the following line to use case-sensitive completion. 40# CASE_SENSITIVE="true" 41 42# Uncomment the following line to use hyphen-insensitive completion. Case 43# sensitive completion must be off. _ and - will be interchangeable. 44# HYPHEN_INSENSITIVE="true" 45 46# Uncomment the following line to disable bi-weekly auto-update checks. 47DISABLE_AUTO_UPDATE="true" 48 49# Uncomment the following line to change how often to auto-update (in days). 50# export UPDATE_ZSH_DAYS=13 51 52# Uncomment the following line to disable colors in ls. 53# DISABLE_LS_COLORS="true" 54 55# Uncomment the following line to disable auto-setting terminal title. 56# DISABLE_AUTO_TITLE="true" 57 58# Uncomment the following line to enable command auto-correction. 59# ENABLE_CORRECTION="true" 60 61# Uncomment the following line to display red dots whilst waiting for completion. 62# COMPLETION_WAITING_DOTS="true" 63 64# Uncomment the following line if you want to disable marking untracked files 65# under VCS as dirty. This makes repository status check for large repositories 66# much, much faster. 67# DISABLE_UNTRACKED_FILES_DIRTY="true" 68 69# Uncomment the following line if you want to change the command execution time 70# stamp shown in the history command output. 71# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 72# HIST_STAMPS="mm/dd/yyyy" 73 74# Would you like to use another custom folder than $ZSH/custom? 75# ZSH_CUSTOM=/path/to/new-custom-folder 76 77# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 78# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 79# Example format: plugins=(rails git textmate ruby lighthouse) 80# Add wisely, as too many plugins slow down shell startup. 81export PATH="/usr/local/bin:/usr/local/sbin:$PATH" 82plugins=(git) 83 84source $ZSH/oh-my-zsh.sh 85 86# User configuration 87 88# export MANPATH="/usr/local/man:$MANPATH" 89 90# You may need to manually set your language environment 91# 日本語を使用 92export LANG=ja_JP.UTF-8 93 94# Preferred editor for local and remote sessions 95# if [[ -n $SSH_CONNECTION ]]; then 96# export EDITOR='vim' 97# else 98# export EDITOR='mvim' 99# fi 100 101# Compilation flags 102# export ARCHFLAGS="-arch x86_64" 103 104# ssh 105# export SSH_KEY_PATH="~/.ssh/rsa_id" 106 107# Set personal aliases, overriding those provided by oh-my-zsh libs, 108# plugins, and themes. Aliases can be placed here, though oh-my-zsh 109# users are encouraged to define aliases within the ZSH_CUSTOM folder. 110# For a full list of active aliases, run `alias`. 111# 112# Example aliases 113# alias zshconfig="mate ~/.zshrc" 114# alias ohmyzsh="mate ~/.oh-my-zsh" 115 116# Lines configured by zsh-newuser-install 117#文字コードをUTF-8に設定 118export EDITORP=vim 119 120# 補完 121autoload -Uz compinit 122compinit 123 124# 補完候補のメニュー選択で、矢印キーの代わりにhjklで移動出来るようにする。 125zmodload zsh/complist 126bindkey -M menuselect 'h' vi-backward-char 127bindkey -M menuselect 'j' vi-down-line-or-history 128bindkey -M menuselect 'k' vi-up-line-or-history 129bindkey -M menuselect 'l' vi-forward-char 130 131# history 132HISTFILE=~/work/dotfils/zsh/.zsh_hist 133HISTSIZE=1000 134SAVEHIST=1000 135setopt extended_history #ヒストリに実行時間も保存 136setopt hist_ignore_dups #直前と同じコマンドはヒストリに追加しない 137 138#vi ライクな操作ができる 139bindkey -v 140# End of lines configured by zsh-newuser-install 141# The following lines were added by compinstall 142 143autoload -Uz compinit 144compinit 145 146# 147# setopt 148# 149 150# cdの後にlsを実行 151chpwd() { ls -ltrG } 152 153 154# ~~~~~~~/etc/shellsファイル ~~~~~~~ 155# List of acceptable shells for chpass(1). 156# Ftpd will not allow users to connect who are not using 157# one of these shells. 158 159/bin/bash 160/bin/csh 161/bin/ksh 162/bin/sh 163/bin/tcsh 164/bin/zsh 165/usr/local/bin/zsh 166 167$ chsh -s /usr/local/bin/zsh 168

.zshrcファイルに関しては参考サイトに記載されているものに対して検索をかけ引っかかったらコメント外し記入、ない場合はファイル下の方にコメントとともに記載しております。
一応、iterm2、terminalのほうでは、oh-my-zshを入れているため、問題なく使えております。

質問

  1. エラーにbashとなっているため、zshを反映させる必要がある?そのためにchsh -s /usr/local/bin/zshとやったつもりではいたのですが認識間違っているでしょうか?

vscodeでもiterm2や、terminalで同じ様に使えるように設定するにはどうすればいいでしょうか?

  1. bashのときはキー操作の設定を.vimrcにて記述してありました。zshの場合では、.zshrcにまとめて記載してしまっていいのでしょうか?

CLI操作に不慣れで至らない点が多々あるかと思いますが、アドバイスいただけると助かります。
よろしくお願いします。

参考サイト

Mac標準のbashからzshに変えた時のメモ
bashからzshに乗り換えの手順

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

zshの起動前にbashの中でsourceを実行しているように見えます。zsh用の設定ファイルをbashに解釈させようとすれば、エラーが出るのは当然でしょう。
chshはログイン時のデフォルトシェルを設定するもので、今現在使用中のシェルを切り替えるものではありません。

chshではなく、zshと打ってその場でzshを起動してみてください(bashの子プロセスとしてzshが起動する)。
.zshrcに問題がないかどうかはここでチェックできます。この段階で.zshrcを変更してsourceを実行すれば、その変更内容がその場で反映されることが確認できるはずです。

投稿2017/11/23 04:34

編集2017/11/23 04:40
KojiDoi

総合スコア13671

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

roronoazoro

2017/11/23 06:11

的確なご回答ありがとうございます。 よくある、.zshrc、.zprofileに記述しデフォルトで読み込ますように設定するのかと思っておりました。 根本であるzshのファイル/usr/local/bin/zshを全く理解していないので少しづつ理解していきたいなと思います。 ありがとうございました。
guest

0

Macは持ってないので詳しく説明は出来ませんが、
VSCodeの統合ターミナルのシェルがzshになっていないためエラーが出ているのだと思います。

VSCodeの以下の設定値はどうなっているでしょうか?

json

1 // ターミナルが OS X で使用するシェルのパス。 2 "terminal.integrated.shell.osx": "zsh", // ← デフォルトはsh 3 // OS X 端末で使用するコマンド ライン引数。 4 "terminal.integrated.shellArgs.osx": [ 5 "-l", 6 "-i" 7 ],

Mac上のパスとかはわからないので環境にあわせて調整して下さい。

投稿2017/11/23 04:16

編集2017/11/23 04:19
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

roronoazoro

2017/11/23 06:11

ご回答ありがとうございます。 "terminal.integrated.shell.osx": "zsh",としたところデフォルトで反映することができました。 助かりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問