Search code examples
for-loopshfreebsdchroot

how to execute for loop inside chroot enviroment


executing this script and it returns nothing in variable i in fact it isn't creating one how to overcome this problem

chroot $ROOT /bin/sh -c "for i in ../autoconf-patch/* ; do patch < $i ; done; ./configure ; make install "

$i returns nothing /bin/sh : Syntax error; ";" unexpected (expecting word) meaning it considers ";" after the command patch < $i which implies that $i is empty and throws that error


Solution

  • Try to use single quotes, for example:

    /bin/sh -c 'i=3; echo $i'
    

    If you use double quotes " the variables will be expanded, you could try this from your example:

    chroot $ROOT /bin/sh -c 'for i in ../autoconf-patch/* ; do patch < $i ; done; ./configure ; make install'