user5047085
user5047085

Reputation:

How to call bash function from script with the same name in the PATH

I have a bash script in the PATH, with name foo

that script looks like so:

#!/usr/bin/env bash

foo_type=`type foo`;

if [[ -z "$foo_type" ]]; then
   . "$HOME/.foo/shell.sh"
fi

'foo' "$@"   ### this calls this script not the bash function in shell.sh

the problem as the comment suggests is the 'foo' doesn't call the sourced bash function, it ends up calling the same script and so I get into an infinite loop and I get this error:

/.../bin/foo: fork: Resource temporarily unavailable

does anyone know how to call the sourced bash function?

Upvotes: 0

Views: 185

Answers (1)

that other guy
that other guy

Reputation: 123490

This is what already happens if there's a bash function defined.

The problem in your script is that foo_type contains something like foo is /.../bin/foo which is not empty, so the script is never sourced and a function is never defined.

You can use set -x to debug this and other problems.

Upvotes: 1

Related Questions