Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • Those $SHELL ... command lines look slightly off to me (and I think it might be better to look at what sudo runs in terms of the arguments, not as a command line). With sudo -u user -i bash -c 'a="b" ; echo $a', sudo gets the strings bash, -c, and a="b" ; echo $a, and escapes and joins those into bash \-c a\=\"b\"\ \;\ echo\ $a running that with $SHELL -c. (sudo doesn't see the single quotes, and doesn't add any.) There, in the command line of the middle shell is the unescaped $a. The command lines here make it appear it would expand before the middle shell runs. Commented Oct 19, 2022 at 12:48
  • (middle as in the user's login shell, as opposed to the outer shell where sudo is started, or the inner shell which is the eventual bash -c the user is actually trying to run. I don't dare make that edit though, since I'm slightly afraid I might myself be lost in the forest of backslashes here) Commented Oct 19, 2022 at 12:49