Home > Software design >  My Bash script ends after entering chroot environment
My Bash script ends after entering chroot environment

Time:09-27

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}"

CodePudding user response:

chroot command will start new child bash process, so rest of your script will not be executed until you quit from child bash process. So instead of /bin/bash just run your script in chroot:

chroot /mnt/gentoo myscript.sh

myscript.sh:

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

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