lolilolicon wrote:
I don't expect more than a dozen who rely on this... but bash
programmers can be quite the perverts, so...
Personally I find those who don't read the man page, and then claim that
documented
behavior is a "bug" are the real "perverts". They expect documented
behavior to work
some way other than is documented... How is that not perverted?
I also find redefining functions with every invocation of bash a major
waste of cpu cycles.
Tons of functions are defined these days with all the support for
bash completions.
Ages ago, back before bash-2 or 3, I did timings and re-reading in all
functions
every invocation of bash is as bad as wiping the environment and
processing it
as a login.
If that's what you want to do, then do it. But I rely on exported
functions to patch
up and reconstruct my environment. I've lobbied heavily in the "sudo"
area to have them
fix their automatic clearing of functions -- and supposedly this will be
fixed in an upcoming
release.
In scripts, I usually define *aliases* (which are processed before
functions)
If you want to execute commands in a script, you must make sure
you are executing those commands. So first, those script better set
the PATH to a
standard path. Any script that doesn't has no right to complain about
this "bug".
2nd, how many scripts define utils into vars:
cp=/usr/bin/cp
$cp ....
-------
The safe way to define cmnds which I try to use in most of my scripts is
to define
them as ALIASES that get expanded before functions.
Example:
#!bin/bash
function true () { false; }
if true; then echo "true==true"; else echo "true==false" ; fi
# above demonstrates what seems to be the bug (a function overriding a
command)
# how it got there, is not entirely relevant
#-- fixed example:
PATH=/sbin:/usr/sbin:/bin:/usr/sbin:$PATH
shopt -s expand_aliases
alias true=$(type -P true)
if true; then echo "true2==true2"; else echo "true2==false2" ; fi
----
The 2nd example works because it defines the PATH and defines an an alias
expansion that translates to the abs path that the alias was defined with.
If people programmed safely to begin with, this wouldn't have come up as
a bug, but a feature.