chroot with working directory specified
1
vote
3
answers
3654
views
Say I want to write wrapper for
chroot
command with the possibility to set working directory otherwise preserving chroot
semantics. Thus semantics should be:
chroot.sh [arg]...
My naive attempt is:
#!/bin/sh
chroot_dir=$1
working_dir=$2
shift 2
chroot "$chroot_dir" sh -c "cd $working_dir; $*"
But this fails to correctly handle:
chroot.sh /path/to/chroot /tmp touch 'filename with space'
I cannot figure out how it should be implemented correctly.
Is it possible using bash only?
On my CentOS 6 system chroot
command doesn't support setting working directory. Probably this is not true on other systems.
Asked by reddot
(296 rep)
Nov 2, 2017, 04:39 PM
Last activity: May 21, 2023, 04:18 PM
Last activity: May 21, 2023, 04:18 PM