2

I would like to know which method is the right one (better, faster, proper).

I'm writing a script that will create an entry in the xfce menu for a list of binary, only if this one is installed on the system (Linux arch based).

Should I check the binary on this way

Check if a program exists from a Bash script

Or should I check if the directory containing the file of the binary is available in /usr/share/ ?

if [ -d "$DIRECTORY" ]; then

Thanks

Community
  • 1
  • 1
Anyone_ph
  • 616
  • 6
  • 15
  • 1
    What if it lacks a folder in `/usr/share/`? I think either of the methods shown in that answer would be the right way to go. – JNevill May 01 '17 at 16:59
  • Each application installed will have his own directory in /usr/share and his binary / simlink in /usr/bin , no issue on this side but thanks for your concern – – Anyone_ph May 02 '17 at 04:22

1 Answers1

1

Here are my two cents:

The test on the linked page, customized for your needs, would be a "better" test. For example:

command -v foo >/dev/null 2>&1 || your failure code here

would be superior than just checking for the directory existence (if [ -d "$DIRECTORY" ]; then), because the directory could exist but the command could fail for some other reason, thus making the link on the XFCE menu useless.

Thus, just checking the directory existence is inferior in my view, since the other test guarantees that the command can be executed.

Jamil Said
  • 2,033
  • 3
  • 15
  • 18
  • 1
    Thanks a lot for your feedback, allow me 2 days before to validate your answer (waiting for other feedback, if any) – Anyone_ph May 02 '17 at 00:32
  • I may forgot an information on my question Each application that have an entry in /usr/bin/ is not all the time the binary (unlike most Linux distribution) nor a symlink but it could be a script launcher that path on the binary in /usr/share/, some are the code python / perl, other binary... Your answer is still working however, (tested on a script python / bash and binary) I just want to make sure that you have all information. – Anyone_ph May 02 '17 at 04:21
  • 1
    After reflexion on your answer, it appear to be the proper way, thanks again for ur feedback – Anyone_ph May 02 '17 at 16:58