Removed recursive script dependency in filename and moved usage lock to start of usage. Should prevent an infinite loop caused by usage checking.

This commit is contained in:
Olivier Poirier 2023-12-05 15:27:09 -06:00
parent ee68a72f60
commit e4f2291427
2 changed files with 21 additions and 16 deletions

View File

@ -2,6 +2,11 @@
# Cuts the name of a single file or list of files out from its path and echoes it.
# Otherwise, does nothing.
lastarg () {
for last in "$@" ; do :; done
echo "$last"
}
IFS='/'
NAME="$(lastarg $0)"
USAGE="Usage: $NAME [filenames...]"

View File

@ -3,25 +3,25 @@
# Requires: <program> <package (Devuan)>
# echo coreutils
NAME="$(filename $0)"
IFS='
if [ -z $USAGE_LOCK ] ; then
export USAGE_LOCK=1
NAME="$(filename $0)"
IFS='
'
MESSAGE="$(lastarg $@)"
AGAINST="$(nolastarg $@)"
IFS=' '
MESSAGE="$(lastarg $@)"
AGAINST="$(nolastarg $@)"
IFS=' '
if ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ) && [ "$2" = "" ] ; then
echo "Usage: $NAME [args to check] <usage string> "
else
CHECK='-h
if ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ) && [ "$2" = "" ] ; then
echo "Usage: $NAME [args to check] <usage string> "
else
CHECK='-h
--help'
if [ "$1" != "" ] ; then
if [ -z $USAGE_LOCK ] ; then
export USAGE_LOCK=1
echo $CHECK | linefirstargdo firstargnthargdo $(( 4 + $# )) firstnthpipedo $(( $# - 1 )) "$AGAINST" invertstatus linematchfirstargdo echo "$MESSAGE"
CODE="$?"
unset USAGE_LOCK
exit $CODE
if [ "$1" != "" ] ; then
echo $CHECK | linefirstargdo firstargnthargdo $(( 4 + $# )) firstnthpipedo $(( $# - 1 )) "$AGAINST" invertstatus linematchfirstargdo echo "$MESSAGE"
CODE="$?"
unset USAGE_LOCK
exit $CODE
fi
fi
fi