Shell 进入 zsh 并从 bash 脚本执行命令
Shell out into zsh and execute commands from bash script
我正在尝试一些虚拟化,所以我一直在使用 vagrant 来提供一个 centos7 虚拟机,现在我正在用应用程序配置它。
我的 vagrant 配置 运行 是一个 bootstrap.sh 文件,它是一个 bash 脚本,我在其中安装了 zsh,然后我想按照 https://github.com/sorin-ionescu/prezto 配置它。
第 1 步是启动 zsh,然后 运行 一些命令。
这是我目前的代码。
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
exec /usr/bin/zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
我希望这是我通过 ssh 进入 VM 时的默认值 shell。它似乎没有工作,vagrant up 步骤没有错误所以我只想知道这是否可能以及这是否正确?
谢谢
exec /usr/bin/zsh
将 运行ning 脚本替换为新的 zsh 进程。之后的所有内容都不会执行。
你基本上有两个选择:
将 zsh 的特定内容放入单独的脚本中,运行 使用 /usr/bin/zsh
:
流浪汉:
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
# run external script
/usr/bin/zsh /home/vagrant/install-prezto.zsh
chsh -s /bin/zsh
/home/vagrant/install-prezto.zsh
:
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
修改脚本,使安装不需要zsh:
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
# use find instead of *zsh* to link files
find "${ZDOTDIR:-$HOME}/.zprezto/runcoms/" -maxdepth 1 -type f -! -name README.md --exec ln -s {} "${ZDOTDIR:-$HOME}/" +
chsh -s /bin/zsh
exec zsh
将您的 shell 替换为 zsh - 但不会以任何方式告诉 zsh 实例在执行的同一点获取,甚至 运行 bash 调用之前执行的相同脚本。
一个简单的解决方法是通过 heredoc 将脚本的其余部分提供给 zsh:
/usr/bin/zsh <<'EOF'
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
EOF
我正在尝试一些虚拟化,所以我一直在使用 vagrant 来提供一个 centos7 虚拟机,现在我正在用应用程序配置它。
我的 vagrant 配置 运行 是一个 bootstrap.sh 文件,它是一个 bash 脚本,我在其中安装了 zsh,然后我想按照 https://github.com/sorin-ionescu/prezto 配置它。 第 1 步是启动 zsh,然后 运行 一些命令。
这是我目前的代码。
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
exec /usr/bin/zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
我希望这是我通过 ssh 进入 VM 时的默认值 shell。它似乎没有工作,vagrant up 步骤没有错误所以我只想知道这是否可能以及这是否正确?
谢谢
exec /usr/bin/zsh
将 运行ning 脚本替换为新的 zsh 进程。之后的所有内容都不会执行。
你基本上有两个选择:
将 zsh 的特定内容放入单独的脚本中,运行 使用
/usr/bin/zsh
:流浪汉:
echo "Installing zsh" yum install -y zsh echo "Configure zsh" # touch /home/vagrant/.zshrc git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" # run external script /usr/bin/zsh /home/vagrant/install-prezto.zsh chsh -s /bin/zsh
/home/vagrant/install-prezto.zsh
:setopt EXTENDED_GLOB for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" done
修改脚本,使安装不需要zsh:
echo "Installing zsh" yum install -y zsh echo "Configure zsh" # touch /home/vagrant/.zshrc git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" # use find instead of *zsh* to link files find "${ZDOTDIR:-$HOME}/.zprezto/runcoms/" -maxdepth 1 -type f -! -name README.md --exec ln -s {} "${ZDOTDIR:-$HOME}/" + chsh -s /bin/zsh
exec zsh
将您的 shell 替换为 zsh - 但不会以任何方式告诉 zsh 实例在执行的同一点获取,甚至 运行 bash 调用之前执行的相同脚本。
一个简单的解决方法是通过 heredoc 将脚本的其余部分提供给 zsh:
/usr/bin/zsh <<'EOF'
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
EOF