[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

`which` and infinite recursion



Howdy.

I just switched from Red Hat to Debian and was wondering why any
invocation of `bash` or `which` caused the forking of hundreds of
processes and (eventually) the complaint:

/bin/bash: fork: Resource temporarily unavailable

I investigated my .bashrc, and found that the offending line was 

export CVS_RSH=`which ssh`

Because `which` is implemented as a bash script, invoking it causes
.bashrc to be read, and `which ssh` to be evaluated, which causes
`which` (a bash script) to be invoked, which causes .bashrc to be
read, which causes `which ssh` to be evaluated, ad infinitum.

On Red Hat, `which` was implemented as a binary, so I was blissfully
untouched by this problem.

Is there any way to avoid it with the Debian `which`? Enclosing the
line in a conditional doesn't work -- even when `bash` is invoked from
a shell in which CVS_RSH is defined and would (presumably) pass that
variable to its children. (As an aside, expressions in backquotes are
evaluated at variable-assignment-time, right? If not, then this code
most definitely wouldn't work.)

i.e.

if [ -n $CVS_RSH ]; then
    export CVS_RSH=`which ssh`
fi

Any suggestions? Or should I just use the Red Hat `which` binary?

Thanks,

--Joe

Attachment: pgpsj_hY0lHvD.pgp
Description: PGP signature


Reply to: