Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a function that I run often from the CLI, so I gave it the short name t:

$ which t
/home/dotancohen/.bin/t

$ cat `which t`
#!/bin/bash
ctags-exuberant -f php.tags --languages=PHP -R

$ ls -lh /home/dotancohen/.bin/t
-rwxr-xr-x 1 dotancohen dotancohen 316 Jan  3 16:58 /home/dotancohen/.bin/t

$ echo $PATH
/home/dotancohen/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/dotancohen/.rvm/bin

However, when I try to run the program, I get a message that I should install another app that also uses the name t:

$ t
The program 'task' is currently not installed. To run 'task' please ask your administrator to install the package 'taskwarrior'

How can I have Bash run /home/dotancohen/.bin/t when I enter t?

share|improve this question
up vote 8 down vote accepted

This is due to the fact that you have t defined as an alias (or a function), you can find it using the type builtin:

type -a t

Aliases, functions (and other shell builtins) take precedence over external executables.

To run the executable t from your PATH, do:

't'

Or

"t"

Or

\t

Note that, just t is not a good name for a file.

share|improve this answer
1  
I completely forgot that t was an alias that I had set up years ago when I used TaskWarrior. I thought that it was the built-in name! Thank you! – dotancohen Jan 24 at 9:11
1  
@dotancohen Let me stress that the bottom line is: don't use which to understand what a command does, since which only reports executables, and rather use the (more portable) type, which can detect functions, aliases etc (and it's a shell builtin, so it will always works as long as you're using a shell which supports it). – kos Jan 24 at 9:59
    
@kos: Noted, thank you! – dotancohen Jan 24 at 10:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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