Some tutorials (such as the Getting Started on linuxcontainers.org) recommend the use of a double-hyphen (--) when using lxc exec to run a program inside a LXD container, as in

$ lxc exec my-container -- apt update

I suspect -- tells lxc exec to pass provided flags to the program, because e.g. lxc exec my-container apt list --upgradable fails with

error: flag provided but not defined: --upgradable

However, I can't find any documentation on the issue. Can someone confirm, or clarify if that's not exactly what it does?

Also, I saw instances where people use -- in different places, e.g.:

$ lxc exec my-container apt -- list --upgradable
$ lxc exec my-container apt list -- --upgradable

What's the difference?

1 Answer 1


Partly this is a duplicate of what does double dash mean.

You ask an interesting question about lxc so let me answer that. In your two examples, both instances of -- tell lxc to not interpret options after that point. The different positioning in this case is irrelevant. However, because you're running a command line in a container, you might want to use -- as part of that command line. Consider the following: I created a file /tmp/bar containing the line --foo. The following commands were run in the container:

root@myContainer:~# echo "here is --foo" >/tmp/bar
root@myContainer:~# echo "this line has no double dash" >> /tmp/bar
root@myContainer:~# cat /tmp/bar
here is --foo
this line has no double dash
root@myContainer:~# exit

Now I'm going to search for that using grep. I need to let grep know that the -- is part of the search pattern, not an option to grep:

$ lxc exec myContainer -- grep -- --foo /tmp/bar
here is --foo

If I use a single -- it gets consumed by the lxc command line and I get the error:

$ lxc exec myContainer grep -- --foo /tmp/bar
grep: unrecognized option '--foo'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.