Results 1 to 9 of 9

Thread: whereis

  1. #1
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    307
    Distro
    Ubuntu 14.04 Trusty Tahr

    whereis

    Is the whereis -commando something that comes with all/most linux-dists?

    Trying to come up a platform-independent way of checking for some package... This works for me in Ubuntu and Arch.

    Code:
    whereis somepackage | awk '{ print $2 }'
    it would return a string (/usr/bin/somepackage in my case) if installed, nothing if not installed. Will this always be the case no matter distro?
    This is my signature

  2. #2
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,086
    Distro
    Ubuntu Mate 15.10 Wily Werewolf

    Re: whereis

    you might want to use
    Code:
    which
    according to http://www.linuxquestions.org/questi...mmands-655031/ whereis only looks in certain hardcoded places, but which searches the whole PATH. i.e. which will actually tell you what binary would be run if you typed the command into a terminal.

  3. #3
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    307
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: whereis

    sweet, thanks a bunch! I will try out which instead. Have a nice day
    This is my signature

  4. #4
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: whereis

    What do you mean by "package"? whereis and which search files, not packages.
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    307
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: whereis

    Sorry, perhaps a bad way of puttin it. I am after a (somewhat distro-independent) way to check if the user has a certain program/tool installed, my script depends on a few tools such as gksu, zenity and wget, and I would like the user to know that he/she doesn't have the required program installed, if that's the case. And
    Code:
    whereis -b wget
    seems sufficient as it's checking for matching installed binaries.

    which that ssam pointed out seemed even better, but which does not seem to return anything.. so I'm unable to use it in a if-statement or so.
    Last edited by DarkAmbient; October 9th, 2012 at 11:18 AM.
    This is my signature

  6. #6
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: whereis

    From what I've seen of configure scripts, autoconf seems to be right up your street. However, bear in mind that it's an exceedingly complete and complex piece of software.

    Perhaps something to consider.

  7. #7
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: whereis

    If the user doesn't have them, they will see the "command not found" error message when they run the script, that should be good enough.
    「明後日の夕方には帰ってるからね。」


  8. #8
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: whereis

    Not sure what language you're using, but I'll assume BASH since you've asked about 'whereis' and 'which'. If the file is not located in $PATH, which won't return anything to stdout except a non-zero exit code. You could use that and the BASH special parameter '$?' to determine whether or not the file is in $PATH. Here's a quickie example that may not be 100% correct but gives you an idea:


    Code:
    #!/bin/bash
    
    echo "What is the program you want to test: "
    read APP
    
    which $APP
    if [ $? -ne 1 ]; then
            printf "The program is in your path.\n"
    else
            printf "The program is not found in your path!\n"
    
    fi

  9. #9
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    307
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: whereis

    Thanks for the help guys! Well, the reason why I would like to check for a certain installed binary is that the script (which you find in my signature) is all-graphical. So upon missing dependency the user should be asked if he/she wants to install (how I havn't figured out just yet as zenity which Is normally used may be the missing dependency) it or simply not continue running the script.
    Last edited by DarkAmbient; October 9th, 2012 at 02:51 PM.
    This is my signature

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •