[lxc-users] lxc exec - support for wildcards and/or variables?

Tomasz Chmielewski mangoo at wpkg.org
Fri Nov 17 16:03:06 UTC 2017


lxc exec does not seem to support wildcards:

# lxc exec $CONTAINER -- touch /tmp/file1 /tmp/file2

# lxc exec $CONTAINER -- ls /tmp/file*
ls: cannot access '/tmp/file*': No such file or directory

# lxc exec $CONTAINER -- ls /tmp/file\*
ls: cannot access '/tmp/file*': No such file or directory


So let's try by setting a variable, which works:

# lxc exec --env LSFILES=/tmp/file* $CONTAINER -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=lxc
TERM=xterm-256color
USER=root
HOME=/root
LSFILES=/tmp/file* <------------------------- it's set, here!
LANG=C.UTF-8


But how to use it from lxc exec?

- this obviously gets expanded on the host:

# lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo $LSFILES


- this is passed as a literal $LSFILES to the container:

# lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo \$LSFILES
$LSFILES


How do I use the variables / wildcards with lxc exec? Say, I want to 
remove all /tmp/somefile* in the container.


Tomasz Chmielewski
https://lxadm.com


More information about the lxc-users mailing list