How to check availability of Perl, its version and presence of a required module?

后端 未结 3 2066
遥遥无期
遥遥无期 2020-12-03 16:07

I have written a Perl script, I just want to give it to every one, for that I planned to write a bash script which is used to test the environment of a user and find whethe

3条回答
  •  抹茶落季
    2020-12-03 16:33

    if perl -MJSON::Any -e 'print "$JSON::Any::VERSION\n"' >/dev/null 2>&1
    then : OK
    else echo "Cannot find a perl with JSON::Any installed" 1>&2
         exit 1
    fi
    

    I often use '${PERL:-perl}' and similar constructs to identify the command (for awk vs nawk or gawk; troff vs groff; etc).

    If you want to test the version of JSON::Any, capture the output from the command instead. If you want to test the version of Perl, add 'use 5.008009;' or whatever number you think is sensible. (It wasn't so long ago that they finally removed Perl 4 from one of the NFS-mounted file systems at work - but that was not the only Perl on the machine - at least, not in the last decade or more!)

提交回复
热议问题