18

I am (somehow) able to run a script:

$ assemble.sh file
... [output]

But which can't find it:

$ which assemble.sh
which: no assemble.sh in (/s/std/bin:/usr/afsws/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/ucb:/bin:/usr/bin:/usr/stat/bin:/usr/X11R6/bin:.
  1. How is this possible?
  2. How can I find where this file is?

I'm using bash.

3
  • Is assemble.sh in your current directory?
    – Keith
    Mar 13, 2011 at 20:54
  • 3
    Probably a dumb question, but is it an alias (i.e. does assemble.sh show up when you type the command alias ? Mar 13, 2011 at 23:04
  • @JamesMcLeod Great guess! It was my case for acme.sh (github.com/Neilpang/acme.sh). After install, acme.sh alias was created and I wondered how acme.sh is called despite not being in PATH var.
    – rlib
    Sep 16, 2017 at 12:38

5 Answers 5

21

Use this command: type assemble.sh

It works in a variety of shells and shows only the first result.

1
  • 9
    Or just type assemble.sh, which is portable (and only shows the first match whereas type -a is a ksh/bash construct to show all matches). Mar 13, 2011 at 22:24
8

Or split the path, and use it in find - the first match should be the solution

find ${PATH//:/ } -maxdepth 1 -name assemble.sh -print -quit

type is of course more easy.

2
  • 2
    This is fairly useful. I didn't know I could split $PATH into its sub components and search each one with find Jan 10, 2013 at 8:33
  • 2
    Didn't try but I guess this can break with spaces in components of PATH
    – nhed
    Jul 15, 2016 at 15:30
4

You may be using bash, but the syntax of the which output shows that you use the old which written in csh. The PATH shows up quoted by parentheses, and the directories in PATH have entries like /opt/SUNWspro/bin and /usr/ccs/bin which only make sense in Solaris. That's consistent: Solaris used the csh which.

Here's my guess: you've got one PATH for bash, and another for csh. This might be a system problem. As I recall, Solaris keeps /etc/profile and /etc/cshrc files for system-wide PATH setting. Those two initialization files might set different PATH variables for different shells. Do "echo $PATH" under bash, and see if it agrees with what the which command prints out as a PATH string.

4
command -v assemble.sh

Info

-v        print a description of COMMAND similar to the `type' builtin
1
  • Also would be useful if you want to find in a modified version of PATH ASSEMBLE=$(PATH=/usr/bin:/usr/local/opt/coreutils/libexec/gnubin command -v assemble.sh)
    – nhed
    Jul 15, 2016 at 15:36
0

You can use locate assemble.sh to find the location of the file.

4
  • No, this shows the location of all (world-)readable files whose name contain assemble.sh, which is irrelevant here. Mar 13, 2011 at 22:22
  • It is not irrelevant at all. Even if he had multiple files called like that locate would also give him the location of the one he wants. assemble.sh is not such a common filename, so he will likely find the file easily (which is what the OP requests).
    – nico
    Mar 13, 2011 at 22:50
  • 2
    Don't you have to updatedb before locate shows results? Mar 14, 2011 at 0:02
  • 1
    Usually updatedb is run daily as a cron job, but yeah, you may have to force it if the file is very recent.
    – nico
    Mar 14, 2011 at 0:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .