1

n00b question.

I have to issue a terminal command that will enter a chroot, issue a command (such as "ls"), and then stay in chroot so the user can type more commands.

Right now this is the best I've got:

cat << EOF | sudo chroot /path/to/chroot
ls
EOF

Unfortunately this exits the chroot as soon as it is finished though.

How can I stay in the chroot?

dnh37
  • 463
  • 2
  • 5
  • 17
  • Possible duplicate of [Pass commands as input to another command (su, ssh, sh, etc)](https://stackoverflow.com/questions/37586811/pass-commands-as-input-to-another-command-su-ssh-sh-etc) – tripleee Nov 25 '17 at 10:15

1 Answers1

3

You could do something like this:

sudo chroot /path/to/chroot sh -c "ls; bash"

This will run ls and then start an interactive bash shell.

larsks
  • 277,717
  • 41
  • 399
  • 399