help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to show the path of a bash script in $PATH?


From: Eduardo A . Bustamante López
Subject: Re: [Help-bash] How to show the path of a bash script in $PATH?
Date: Mon, 6 Apr 2015 08:02:41 -0500
User-agent: Mutt/1.5.23 (2014-03-12)

I agree with Greg. It seems as if you're following an incorrect train of
thought to solve a problem (you could perhaps just tell us about your *real*
problem, not about what you think solves it).

Also, just doing a simple search in PATH doesn't work. You'd have to check if
bash is running in POSIX mode, or if the `sourcepath' option is set. These
change the way the `.' command does its lookup.

You could do the following:

    address@hidden:~/t$ PATH=; (set -T; trap "(return 2>/dev/null) && echo 
\$BASH_SOURCE && return" DEBUG; . a)
    a
    address@hidden:~/t$ PATH=; (set -T; set -o posix; trap "(return 
2>/dev/null) && echo \$BASH_SOURCE && return" DEBUG; . a)
    a
    address@hidden:~/t$ PATH=baz:foo:bar; (set -T; trap "(return 2>/dev/null) 
&& echo \$BASH_SOURCE && return" DEBUG; . a)
    baz/a
    address@hidden:~/t$ PATH=foo:baz:bar; (set -T; trap "(return 2>/dev/null) 
&& echo \$BASH_SOURCE && return" DEBUG; . a)
    foo/a
    address@hidden:~/t$ PATH=baz:foo:bar; (set -T; set -o posix; trap "(return 
2>/dev/null) && echo \$BASH_SOURCE && return" DEBUG; . a)
    baz/a
    address@hidden:~/t$ PATH=baz:foo:bar; (set -T; shopt -s sourcepath; trap 
"(return 2>/dev/null) && echo \$BASH_SOURCE && return" DEBUG; . a)
    baz/a
    address@hidden:~/t$ PATH=baz:foo:bar; (set -T; shopt -u sourcepath; trap 
"(return 2>/dev/null) && echo \$BASH_SOURCE && return" DEBUG; . a)
    a

But again, it seems that you're asking the wrong question.

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]