[Surfraw-devel] [Fwd: Bug#269982: /etc/bash_completion.d/surfraw breaks bashes pwd command]

Christian Surchi csurchi@debian.org
Sat, 04 Sep 2004 21:21:33 +0200


-----Messaggio Inoltrato-----
From: Brian McDonald <weifgvjlpmvr@spammotel.com>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Bug#269982: /etc/bash_completion.d/surfraw breaks bashes pwd command
Date: Sat, 04 Sep 2004 13:42:04 -0400

Package: surfraw
Version: 2.0.2-1
Severity: critical
Tags: patch
Justification: breaks unrelated software



-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i586)
Kernel: Linux 2.4.27-1-586tsc
Locale: LANG=C, LC_CTYPE=C

Versions of packages surfraw depends on:
ii  debconf                1.4.30.2          Debian configuration management sy
ii  dillo [www-browser]    0.8.1-1           GTK-based web browser
ii  elinks [www-browser]   0.9.1+0.9.2pre4-1 Character mode WWW/FTP browser
ii  konqueror [www-browser 4:3.2.2-1         KDE's advanced File Manager, Web B
ii  lynx [www-browser]     2.8.5-1           Text-mode WWW Browser
ii  mozilla-browser [www-b 2:1.6-5           Mozilla Web Browser - core and bro
ii  mozilla-firefox [www-b 0.8-12            lightweight web browser based on M
ii  w3m [www-browser]      0.5.1-1           WWW browsable pager with excellent

-- debconf information:
  surfraw/surfraw-v2-upgrade:
* surfraw/surfraw-path:

When issueing the `pwd` command at the bash prompt I get the following
error:

brian@4[brian]$ bash
brian@4[brian]$ pwd
/home/brian
bash: pwd: write error: No such file or directory
brian@4[brian]$

if I change the last line of /etc/bash_completion.d/surfraw from 

type -p surfraw >&- && complete -F _surfraw surfraw sr

to

type -p surfraw >/dev/null 2>&1 && complete -F _surfraw surfraw sr

and start a new shell, the error messages goes away.

Looking up the ` >&- ` construct in the bash manpage although ambiguous,
seems to correspond with the following definition:

Duplicating File Descriptors
    The redirection operator

           [n]<&word

    is used to duplicate input file descriptors.  If word expands to one or
    more digits, the file descriptor denoted by n is made to be a  copy of
    that  file  descriptor.   If the  digits in word do not specify a file
    descriptor open for input, a redirection error occurs.  If word evalu-
    ates  to  -,  file descriptor n is closed.  If n is not specified, the
    standard input (file descriptor 0) is used.

    The operator

           [n]>&word

    is used similarly to duplicate output file descriptors.  If	 n  is  not
    specified, the standard output  (file descriptor 1) is used.  If the
    digits in word do not specify a file descriptor open for output, a
    redirection error occurs. As a special case, if n is omitted, and word
    does not expand to one or more digits, the standard	output and standard
    error are redirected as described previously.

I take this to mean that stdout is being copied to stdout and then stdout is
closed. I think closing stdout is the problem.
I also think testing for a condition after the function has already been
loaded into the enviroment may unnesessarily bloat the enviroment, so my
modification to the file wraps the function in the test.
Note my scripting abilities are poor but the following works for me:

diff surfraw surfraw.new

1a2
> if [ `type -p surfraw` ] ; then
26c27,28
< type -p surfraw >&- && complete -F _surfraw surfraw sr
---
> complete -F _surfraw surfraw sr
> fi