Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:10:42+00:00 2026-06-08T22:10:42+00:00

Say I have: >which -a foo /bin/foo /usr/bin/foo I want something like: >foo Warning:

  • 0

Say I have:

>which -a foo
/bin/foo
/usr/bin/foo

I want something like:

>foo
Warning: multiple foo in PATH
... foo gets executed ...

This functionality would have saved me really really lots of time today.
I should have guessed this is happening earlier but the problem was unclear
to me at the beggining and I started to dig in quite opposite direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:10:44+00:00Added an answer on June 8, 2026 at 10:10 pm

    Well, you can do it, but it is not so easy as you may think.

    First, you need to create a function that will check
    all directories in the PATH, and look there for the command you try to run.
    Then you need to bind this function to the DEBUG trap of your current shell.

    I wrote a small script that does that:

    $ cat /tmp/1.sh
    
    check_command()
    {
        n=0
        DIRS=""
        for i in $(echo $PATH| tr : " ")
        do 
            if [ -x "$i/$1" ]
            then 
                n=$[n+1]
                DIRS="$DIRS $i"
            fi
        done
        if [ "$n" -gt 1 ]
        then
          echo "Warning: there are multiple commands in different PATH directories: "$DIRS
        fi
    }
    
    preexec () {
        check_command $1
    }
    preexec_invoke_exec () {
        [ -n "$COMP_LINE" ] && return  # do nothing if completing
        local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
        preexec "$this_command"
    }
    trap 'preexec_invoke_exec' DEBUG
    

    Example of usage:

    $ . /tmp/1.sh
    $ sudo cp /bin/date /usr/bin/test_it
    $ sudo cp /bin/date /bin/test_it
    $ test_it
    Warning: there are multiple commands in different PATH directories:  /usr/bin /bin
    Wed Jul 11 15:14:43 CEST 2012
    $ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have SELECT name FROM table which gives me something like foo
Say you have a schema that looks something like this Foo FooId Bar BarId
Say I have this example: char const * const foo( ){ /* which is
Let's say we have a class foo which has a private instance variable bar
Say I have a www.foo.com domain which is setup to load my app on
Let's say we have def Foo(Bar=0,Song=0): print(Bar) print(Song) And I want to assign any
Let's say I have a class FOO. I want to have a std::vector of
Let's say I have file foo.txt in which I have one digit which is
Say I have a method Foo() and I want to measure the time in
Say you have, foo = 'bar' d = {'a-key':'a-value'} And you want d =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.