Just a little issue with a "find" command

Hi everyone !

I’m actually working on Kaldi, which unfortunately doesn’t provide any “install” target for Make. To install generated binaries, I use this command :

for b in find $pwd ! -name '*.so' ! -name 'Makefile' -type f -exec test -x {} \; -print
do
install -m 755 $b %{buildroot}%{_bindir}/$b
done

Unfortunately, it doesn’t just install the binaries but the directories which contain these binaries. What am I doing wrong ?

Thanks for any further help.

Regards.
Benjamin

Maybe you could show yourself (and us) what the install statement(s) look like with this test variant of your coding:

for b in `find $pwd ! -name '*.so' ! -name 'Makefile' -type f -exec test -x {} \; -print` do
         echo  755 $b %{buildroot}%{_bindir}/$b
done                      

Oh yes, and please you CODE tags, not QUOTE tags around computer text. It is the # button in the tool bar of the post editor.

You told install command to install under full path, containing directories. Please read your install command once more carefully. You need to strip directory part from find output.

I know. But I don’t know how stripping out the directory.

A guy of the Alionet forum gave me the solution. But thanks anyway.

Then why didn’t you ask for that. I know of two solutions (there may be more as so often in Unix/Linux)

basename path

see

man basename
${path##*/}

see

man bash

in the section Parameter Expansion.

I don’t know why I didn’t think about $basename. So for now, here is the command :
find $pwd ! -name ‘*.so’ ! -name ‘Makefile’ -type f -executable -exec install -m 755 {} %{buildroot}%{_bindir} ;

Well, the problem with writing scripts is often that you can not be clairvoyant and know that such a thing as basename exists. You can only know that after someone else tells, or one happens to read it somewhere, or similar. And even then you have to remember it on the right moment.

There are a lot of those tiny, but usefull tools, but where to look for them?

That is why asking here can save a lot of time and frustration :slight_smile:

And in these cases, you’re thanking God someone else knows what you don’t :). And then thanking the person who helped you so thanks you :).