On Mon  2 Apr 2018 at 08:14:40 -0700, Ian Zimmerman wrote:
> This pipe is something of a Rube Goldberg device.  Why not pass the
> variable directly:
> 
> chroot $ROOT /usr/bin/env PS1="(chrooted to $HOST) $PS1" bash

  That is  of course a lot  more elegant,  I must  have been half-asleep
when I wrote that pipe the first time.

> In fact I think I see a problem with your way: the chrooted shell sees a
> command like
> 
> export PS1=You have chrooted into 'eden' from root
> 
> which obviously cannot work.  (No clue if that is why it breaks for
> Thelma, and no clue why it works for you :P)

  What my syntax is  doing is to let the $PS1  inside the PS1 definition
be evaluated  by the  chroot shell.  Suppose you  run this  command with
HOST=eden and ROOT=/mnt/eden:

    echo 'export PS1="(chroot '$HOST') $PS1"; exec <dev/tty' | exec chroot 
$ROOT /bin/bash -i

The parent shell will translate this into

    echo 'export PS1="(chroot 'eden') $PS1"; exec </dev/tty' | exec chroot 
/mnt/eden /bin/bash -i

This is where the purpose of the 's around $HOST shows: $HOST is outside
the single quotes,  so gets substituted,  while  the rest of the string,
notably $PS1,  remains the same.  The child shell will therefore receive
input

    export PS1="(chroot eden) $PS1"; exec </dev/tty

which will prepend the desired text to the child shell’s prompt.
  But indeed why bother if the $PS1  of the parent shell will do just as
well?

-- 
Sebastiaan L. Zoutendijk | slzoutend...@gmail.com

Reply via email to