Reputation: 824
How do I find the directory of a command in bash?
I'm not looking which
For example which cat
tells me /bin/cat
.
I'm looking for something which only gives me /bin
Upvotes: 0
Views: 61
Reputation: 37237
You can also use bash
builtin string substitution:
CAT=$(which cat)
echo "${CAT%/*}"
Output:
/bin
Upvotes: 1
Reputation: 3760
Use dirname /bin/cat
/bin
Similarly you can use basename /bin/cat
cat
Upvotes: 4