I alias pandoc='~/.cabal/bin/pandoc' because I don't want to change my $PATH order just for this one program.

In general, programs I installed in /opt/, ~/.cabal/, and so on should precede defaults in /bin/, but I don't want bash to search through thirteen special directories just to find /bin/cat, which seems like it should be fast and immediate.

Is there a more appropriate middle-ground than simply aliasing over particular programs whenever they seem to be executing the wrong version?

1 Answer 1


Bash maintains a table where it caches the full path to executables - see, e.g., http://bradconte.com/bash-path-hashing. The first time you invoke /bin/cat in a Bash session, the full path to it will be stored in this table. The second time you run /bin/cat, Bash doesn't actually search the search path again. In a sense, that's fast and immediate.

You can even use the hash (Bash) built-in in the way it's explained in this nice answer, in order to cache the full path to the pandoc executable:

hash -p ~/.cabal/bin/pandoc pandoc

From help hash:

hash: hash [-lr] [-p pathname] [-dt] [name ...]
    Remember or display program locations.

    Determine and remember the full pathname of each command NAME.  If
    no arguments are given, information about remembered commands is displayed.

      -d                forget the remembered location of each NAME
      -l                display in a format that may be reused as input
      -p pathname       use PATHNAME is the full pathname of NAME
      -r                forget all remembered locations
      -t                print the remembered location of each NAME, preceding
                each location with the corresponding NAME if multiple
                NAMEs are given
      NAME              Each NAME is searched for in $PATH and added to the list
                of remembered commands.

    Exit Status:
    Returns success unless NAME is not found or an invalid option is given.
  • oh, awesome! Nice to know; thanks for taking the time to answer. Feb 24, 2015 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.