0

Running Ubuntu 16.04 I want to install (programmatically) getopts if it is not installed.

After this post I am doing something like this:

GETOPTS=getopts

if [$GETOPTS==""] 
   then
   echo "Installing getopts"
   sudo apt-get install -y libperl4-corelibs-perl
fi

But it is not working.

Any Idea how to do this?

IgorAlves
  • 1,162

1 Answers1

1

When you want to check if some tool you start from the command line is installed the following line would work:

if [ "`which someCommand`" = "" ]

The which command checks for the full file name of the executable of someCommand and if the file is not found the body of the if statement is executed.

However this assumes that someCommand is a command you can start from the command line (terminal etc.).

In your case you probably want to check if the file /usr/share/perl5/getopts.pl exists.

According to this question this can be done using the following check:

if [ ! -f /usr/share/perl5/getopts.pl ]

This statement will check if some file not exist...