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

Andrey Repin anrdaemon at yandex.ru
Sat Nov 18 04:49:32 UTC 2017


Greetings, Tomasz Chmielewski!

> lxc exec does not seem to support wildcards:

It's not exec, it's you.

> # 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

Of course.
lxc exe does exactly what you said to do.

> 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.

Do what your host do - allow shell to expand in the container.
Since wildcard expansion is done by the shell (surprize!), not by the executed
program, you'd have to run the command through shell in the container.
Which you are not doing currently. Same as if you run "ls '/tmp/file*' " on
host.


-- 
With best regards,
Andrey Repin
Saturday, November 18, 2017 07:45:47

Sorry for my terrible english...



More information about the lxc-users mailing list