how to access $user from commandline?
You need to define the $user variable first. You can run the drush command as a particular user by specifying --user on the command line:

drush --user='admin' ev 'global $user; print_r($user);'


If you don't specify a user, drush runs as anonymous by default.

Or, you can do it like this:

drush ev '$user = user_load_by_name("admin"); print_r($user);'


It will display this:

stdClass Object
(
    [uid] =&gt; 1
    [name] =&gt; admin
    [pass] =&gt; *****
    [mail] =&gt; info@example.com
    [theme] =&gt; 
    [signature] =&gt; 
    [signature_format] =&gt; filtered_html
    [created] =&gt; 1443708895
    [access] =&gt; 1515415027
    [login] =&gt; 1515411954
    [status] =&gt; 1
    [timezone] =&gt; Europe/London
    [language] =&gt; 
    [picture] =&gt; 0
    [init] =&gt; info@example.com
    [data] =&gt; 
    [uuid] =&gt; f6800524-c092-4abc-abcd-f71d091623cd
    [roles] =&gt; Array
        (
            [2] =&gt; authenticated user
        )

    [force_password_change] =&gt; 0
)