linux - 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}"
解决方案
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}"
推荐阅读
- swift - Do I have to downcast or am I missing something?
- python - 在 Python 中按部分字符串计数
- python - 如何将二进制 numpy 数组更改为 int?
- python - 如何在 Canvas 中重复 def 函数?
- java - TextView:空指针异常
- android - 有没有办法使用 Room 观察数据库上的特定操作?
- c++ - 有没有办法简化/整合这个发送功能
- c# - 在 sql asp.net mvc 5 中使用 linq 时如何正确提取数据?
- php - Laravel 缓存正在返回旧值
- plugins - Roblox Studio - 如何在游戏开始前运行脚本?