With zsh
(note that which
is only built in tcsh
or zsh
, in other shells it can give random results, use type
in Bourne like shells):
$ which -m '*latex'
/usr/bin/arlatex
/usr/bin/dvilualatex
/usr/bin/fig4latex
/usr/bin/latex
/usr/bin/lualatex
/usr/bin/pdflatex
/usr/bin/pod2latex
/usr/bin/pslatex
Or (if you only want to consider executables and not functions, aliases...):
$ ls -ld $^path/*latex(-*DN)
lrwxrwxrwx 1 root root 53 Apr 8 03:14 /usr/bin/arlatex -> ../share/texlive/texmf-dist/scripts/bundledoc/arlatex*
lrwxrwxrwx 1 root root 6 Apr 8 03:51 /usr/bin/dvilualatex -> luatex*
lrwxrwxrwx 1 root root 55 Apr 8 03:51 /usr/bin/fig4latex -> ../share/texlive/texmf-dist/scripts/fig4latex/fig4latex*
lrwxrwxrwx 1 root root 6 Apr 8 03:51 /usr/bin/latex -> pdftex*
lrwxrwxrwx 1 root root 6 Apr 8 03:51 /usr/bin/lualatex -> luatex*
lrwxrwxrwx 1 root root 6 Apr 8 03:51 /usr/bin/pdflatex -> pdftex*
-rwxr-xr-x 1 root root 10340 May 20 2013 /usr/bin/pod2latex*
lrwxrwxrwx 1 root root 54 Apr 8 03:14 /usr/bin/pslatex -> ../share/texlive/texmf-dist/scripts/texlive/pslatex.sh*
With other Bourne-like shells, you could do:
searchPATH() (
pattern=$1
IFS=:; set -f; set -- $PATH
set +f; IFS=
for i do
for j in "$i"/$pattern; do
[ -x "$j" ] && printf '%s\n' "$j"
done
done
)
And then:
$ searchPATH '*latex'
/usr/bin/arlatex
/usr/bin/dvilualatex
/usr/bin/fig4latex
/usr/bin/latex
/usr/bin/lualatex
/usr/bin/pdflatex
/usr/bin/pod2latex
/usr/bin/pslatex
That should work more the most common values of $PATH
. It will omit the entries in the current directory if $PATH
ends in :
(like /bin:/usr/bin:
)
find /tmp/test -name '*.txt' \
-exec bash -c './thulac < "$(readlink -f {})" > "/mnt/tokenized/$(basename {})"' \;
Use find to search for files and to execute commands on the results. With bash -c 'command'
you are able to execute multiple $().
Use readlink -f {}
to create the full path to the result.
Use basename {}
to strip the path from the result.
Best Answer
(don't use
which
).Of course, that won't work if
$executable
is a shell builtin, function or alias. I'm not aware of any shell wheremysql
is a builtin. It won't be a function or alias unless you defined them earlier, but then you should know about it. An exception to that could bebash
which supports exported functions.