koalaman/shellcheck

Feature Request: Partial runtime validator backed by Morbig for POSIX shell

Opened this issue · 0 comments

I have implemented a very in development tool for use with POSIX shells which does two things currently. Firstly, it rigorously validates the syntax of the script. Secondly, it reports back on stdout in a space-delimited fashion the programs used but which could not be found on any value found in $PATH. On error, a non-zero exit code is set with an error message, usually the like and column of a syntax error of the user's script where the error occurred.

This is great and all. But would this be of help to users of shellcheck to have some header like the following?

#! /usr/bin/env sh

if ! command -v detect_programs_called_from_script > /dev/null 2> /dev/null
then
    missing_programs=detect_programs_called_from_script  < "$(pwd)"'/'"$0" 
    if [ $? != 0 ] ; then
        echo "Script self-terminating early; detected syntax error"
        echo $missing_programs
        exit 1
    fi
    if [ $missing_programs != "" ] ; then
        echo "Script calls programs which could not be resolved."
        echo "These programs are: $missing_programs"
        exit 1
    fi
fi

For many installers like Nvidia's or Guix's, this would be very helpful. But the use case may be too niche to bother with. There could also be outright technically superior alternatives which should be used instead. I don't know. I'm looking for some feedback.