bash < 3 support removal step 3: update documentation.

master
Ville Skyttä 2009-10-22 11:37:35 +03:00
parent 1c53627fa2
commit e16e072659
1 changed files with 17 additions and 77 deletions

94
README
View File

@ -12,48 +12,20 @@ if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
(if you happen to have *only* bash >= 2.04, see further if not)
(if you happen to have *only* bash >= 3, see further if not)
If you don't have the package readily available for your distribution, or
you simply don't want to do this, put the bash_completion file somewhere
on your system and source it from either /etc/bashrc or ~/.bashrc, as
explained above.
Here's another possible way of doing that from /etc/bashrc:
# Check for interactive shell.
if [ -n "$PS1" ]; then
if [ $bmajor -eq 2 -a $bminor '>' 04 ] || [ $bmajor -gt 2 ]; then
if [ -r /etc/bash_completion ]; then
# Source completion code.
. /etc/bash_completion
fi
fi
fi
unset bash bminor bmajor
This code checks that the version of bash that is parsing the code is
later than 2.04 and, if so, sources the bash completion code.
While this code may, at first, seem overly complex, the advantage of
using it is that it will also parse correctly when interpreted by bash
1.x. If you have bash 1.x and bash 2/3.x users on your system, you
must avoid using constructs that were not valid under 1.x syntax.
If your system has an /etc/profile.d directory, you might instead want
to add a script called bash_completion.sh to that directory. Add the
above code, preceded by the following:
# Check for bash.
[ -z "$BASH_VERSION" ] && return
In this case, all *.sh scripts in /etc/profile.d are sourced from
/etc/bashrc by Bourne-like shells, so you need the extra check for bash
in order to avoid sourcing the rest of the script if a shell other than
bash is running.
For your convenience, a sample bash_completion.sh file is included in
the package.
A more elaborate way that takes care of not loading on old, unsupported
bash versions as well as some other conditions is included in the bash
completion package as bash_completion.sh. If your system has the
/etc/profile.d directory and loads all files from it automatically,
you may place the file in it. If not, place the file somewhere on your
system and source it from /etc/bashrc or ~/.bashrc, or copy its contents
to one of those files.
If you're using MacOS X, /etc/bashrc is apparently not sourced at all.
In that case, you should put the bash_completion file in /sw/etc and add
@ -72,31 +44,6 @@ place to do this.
TROUBLESHOOTING
---------------
If you get errors about 'complete' or 'compgen' not accepting the -g
flag, you are probably running bash 2.05 and should either apply the
group completion patch, download a prepatched bash binary of 2.05, or
upgrade to 2.05a or later.
If you find that some commands, such as 'cd /usr<Tab>', end with a
trailing space instead of appending a /, you are probably running the
base version of bash 2.05, which suffers from a bug that causes the
'-o filenames' option to the complete built-in to be ignored. You can
fix this by applying the following official patch from the bash
maintainer:
ftp://ftp.gnu.org/gnu/bash/bash-2.05b-patches/bash205b-006
If you get errors about 'complete' not accepting the -o flag, you are
probably running bash 2.04. In this case, you should upgrade to bash
2.05a or later. However, we have endeavoured to make the code detect
this version of bash and work around this issue, so please inform us
if you still encounter this error.
Copies of the patches and prepatched versions of bash are available
from:
http://www.caliban.org/bash/
If you find that a given function is producing errors under certain
circumstances when you attempt completion, try running 'set -v' or
'set -x' prior to attempting the completion again. This will produce
@ -397,23 +344,16 @@ guidelines in mind:
start interpreters. Use lightweight programs such as grep(1), awk(1)
and sed(1).
- Use the full power of bash 2.x. Programmable completion has only
been available since bash 2.04, so you may as well use all the
features of that version of bash to optimise your code. However, be
careful when using features added since 2.04, since not everyone
will be able to use them. Be ESPECIALLY careful of using features
exclusive to 3.x, as many people are still using 2.x.
- Use the full power of bash >= 3. We no longer support earlier bash
versions, so you may as well use all the features of that version of
bash to optimise your code. However, be careful when using features
added since bash 3.0, since not everyone will be able to use them. Be
ESPECIALLY careful of using features exclusive to 4.x, as many people
are still using 3.x.
For example, here strings (<<<) were not added until 2.05b, so don't
use them for the time being.
Similarly, 3.0 added the use of the regex operator '=~', commonly
found in Perl and Ruby. Whilst this is very useful, it's not yet
safe to assume its ubiquity.
On the other hand, extended globs were added in bash 2.02 and often
enable you to avoid the use of external programs, which are
expensive to fork and execute, so do make full use of those:
For example, extended globs often enable you to avoid the use of
external programs, which are expensive to fork and execute, so do
make full use of those:
?(pattern-list) - match zero or one occurrences of patterns
*(pattern-list) - match zero or more occurrences of patterns