1

This question already has an answer here:

I am on OSX and installed Homebrew to get the GNU coreutils. I wanted gsort to be used instead of the preinstalled sort command so I created a symlink to gsort. My limited experience tells me that running sort from the CL or in a script will use gsort, however that's not what's happening:

$ which gsort; which sort
/usr/local/bin/gsort
/usr/local/bin/sort
$ ll /usr/local/bin/ | fgrep sort
1083450 lrwxr-xr-x  1 alex  admin  -   34B Mar 23 15:56:52 2016 gsort@ -> ../Cellar/coreutils/8.25/bin/gsort
1083466 lrwxr-xr-x  1 alex  admin  -   35B Mar 23 15:56:52 2016 gtsort@ -> ../Cellar/coreutils/8.25/bin/gtsort
1088327 lrwxr-xr-x  1 alex  admin  -   34B Mar 23 16:57:41 2016 sort@ -> ../Cellar/coreutils/8.25/bin/gsort
$ echo ${PATH} 
/usr/local/opt/gnu-sed/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ gsort --version | fgrep GNU
sort (GNU coreutils) 8.25
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
$ /usr/local/bin/sort --version | fgrep GNU
sort (GNU coreutils) 8.25
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
$ sort --version | fgrep GNU
sort (GNU coreutils) 5.93
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.

Notice that when checking the version of gsort and sort (when using the absolute path to the symlink) it properly shows the newer coreutils version, but just running sort still gives me the old, preinstalled version. Can anyone tell me why?

marked as duplicate by Gilles bash Mar 24 '16 at 23:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

If you launched sort in this same shell session before installing your symlink, bash has cached the path-search results. Use type sort to check whether it answers sort is hashed (/usr/bin/sort).

  • Thanks. I didn't know about hash or type. – Linoob Mar 24 '16 at 17:20

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