首页 > 解决方案 > My Bash script ends after entering chroot environment

问题描述

My question:

After the following lines in my script, the script ends unexpectedly. I am trying to enter chroot inside of a bash script. How can I make this work

I am writing a script that installs Gentoo

echo " Entering the new environment"


chroot /mnt/gentoo /bin/bash 

source /etc/profile 

export PS1="(chroot) ${PS1}"

标签: linuxbashunixsh

解决方案


chroot 命令将启动新的子 bash 进程,因此在您退出子 bash 进程之前,不会执行脚本的其余部分。因此,只需在 chroot 中运行您的脚本,而不是 /bin/bash:

chroot /mnt/gentoo myscript.sh

myscript.sh:

#!/bin/bash
echo " Entering the new environment"

source /etc/profile 
export PS1="(chroot) ${PS1}"

推荐阅读