[sudo-users] Test for -E support

Jeffrey Walton noloader at gmail.com
Sat Mar 28 12:17:23 MDT 2020

Hi Everyone,

I've got a recipe that echo's a password during an install:

    echo "$password" | sudo -E -S make install

Some of the older machines in my testing environment does not support
-E. The first thing I need is, detect the problem. Preferably the test
would not use a password. It just tests for the -E option.

My attempts (like below) result in a password prompt that I would like to avoid.

    sudo -E ls

My second attempt used the following. It produces no output on Ubuntu
18.04, but produces the following out on an old PowerMac:

    $ sudo -E -h 1>/dev/null
    sudo: illegal option `-E'
    usage: sudo -K | -L | -V | -h | -k | -l | -v

So I'm thinking I can check for -E with:

    NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`

And then:

    # PowerMac
    $ NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`; echo $NO_E_OPT
    # Ubuntu
    $ NO_E_OPT=`sudo -E -h 2>&1 | grep -i -c illegal`; echo $NO_E_OPT

Does that look about right? Or is there a better way to do this?

Thanks in advance.

More information about the sudo-users mailing list