This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Workaround for silent linkage errors

Hash: SHA1

According to Phil Betts on 11/9/2007 10:15 AM:
> It is designed to be installed in /etc/profile.d and uses one of
> two methods:

Won't work as posted, since profile.d is loaded by all bourne-style
shells, but 'declare -r' is bash-specific.  Why not propose a patch for
/etc/profile in the base-files package instead, to change the default
cygwin prompt for new installations?  And even if you want to keep this as
a profile.d script, at least do some sanity checking that you are only
installing it for bash.

> I have made 
> the variable read-only so that should a user want to override it, 
> they'd have to take extra steps and in doing so would learn why it 
> is set up that way.

Yuck - since the variable is made read-only in a profile.d script, the
only way to undo that is to edit the profile.d script.  Ouch.  At least
allow for an environment variable override, rather than requiring editing
a system file.

> It's by no means a perfect solution, because the error is only
> detected if the last command executed before the prompt failed.

Have you looked into making your PROMPT_COMMAND use PIPESTATUS?  For that
matter, I avoid PROMPT_COMMAND, and get all my exit statuses at once with
this PS1:

PS1='\[\033[0m\]\n\[\033[32m\]\u@\h \[\033[35m\]'\
'(${PIPESTATUS[*]}) \[\033[33m\]\w\[\033[0m\]\n\$ '

> This might be considered a better solution, as it also works inside 
> functions (if set -E is used) and sourced scripts, but it has the 
> disadvantage of printing the message twice if it was the last command 
> in the script which failed - once as the error is trapped within the 
> script, and once as the return status of the script is detected.

Ah, but you could have your trap change the return status to some other
failure value, so that the message doesn't print a second time.  But you
are right that trapping ERR is prone to be lost in user scripts.

> I've lifted the copyright message from Eric Blake's script,

Fine by me, since I lifted it from somewhere else (I think it was from the
GNU Coding Standards recommendations for how to make short files maximally
reusable while still declaring copyright, unlike what 'public domain'

- --
Don't work too hard, make some time for fun as well!

Eric Blake   
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]