X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:to:from:subject:date:message-id:references
	:mime-version:content-type:content-transfer-encoding; q=dns; s=
	default; b=DMKzxeAxpnwHsqfO+2PGfjg4r2bRQXpUE1KH6d10LJwC5hM0JgTx4
	cdcu0svG+52OWdd3nDEkBt3A2YE3fiOom48H9ZIeOSYBX5VIacMLgaZchThMu7Ts
	4rZG0U75Rnb/9bgOxe8N4zJpEGsViCoFSajdPWzsVeR4TeW/QlOz5c=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:to:from:subject:date:message-id:references
	:mime-version:content-type:content-transfer-encoding; s=default;
	 bh=MD/P41xcoPN7iFag1i/fhAoMnNs=; b=CNrX2vWusXQcE88jW3CiLxh3OpbW
	5ChfDNISEfgsjGL2/eYe3wfBeJF9TUPbYhjiSm953J4PzvLbzVqtWT1a4bZ1/pLU
	nOXUVmV8LR++ov7CD4ZNuXWeMNRtokDOeRbiLGF1o145Aqud1A7Vl3Wz2Rj2Iqhb
	9e9oq2xoQem7pOk=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=ha, U*user, s_32_31_, user@host
X-HELO: plane.gmane.org
To: cygwin@cygwin.com
From: Andrew Schulman <schulman.andrew@epa.gov>
Subject: Re: Change PS1 when run as administrator
Date: Tue, 15 Mar 2016 12:33:32 -0400
Lines: 20
Message-ID: <98egebtkn3kakah2g5m9nhr393mag7qm8j@4ax.com>
References: <F7CDFE45-BFA7-4599-B510-B40BCA19142F@etr-usa.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Archive: encrypt
X-IsSubscribed: yes

> I just came up with this recipe to change the default PS1 value to use red for the user@host part of the prompt and to change the $ character to a #:
> 
>     if id | grep -qi 'member of administrators group'
>     then
>         export PS1=$(echo "$PS1" | sed -e 's_32_31_' -e 's_\\\$_#_')
>     fi
> 
> I’m not certain the string match on the output of id(1) works everywhere.  Is there a better way to check for admin privileges under Cygwin?  You can’t check for UID or EUID == 0, for example, as you’d do on a true POSIX system.

Ha!  Yes, there is:  see
https://cygwin.com/ml/cygwin/2015-02/msg00057.html.  The magic test is

id -G | grep -qE '\<(544|0)\>'

where 544 is the Administrators group, and 0 is the root group in case the
old root group entry is present in /etc/group.

For example:

id -G | grep -qE '\<(544|0)\>' && echo admin || echo user


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

