smeserver-gitutils/parse-list.sh

47 lines
1.1 KiB
Bash
Raw Normal View History

2023-06-02 03:38:02 +02:00
#!/bin/bash
#
# Run script against every item in input file
if [[ -z $1 ]] ; then
echo "parse a list of parameters and execute script with those parameters"
echo "parse-list.sh <param file> <script> [<noisy> <additional> <additional> <additional>]"
echo "<param file> = name of file containing parameters"
echo "<script> script to run (e.g. rename-e-smith-pkh.sh)"
echo "optional params can appear in any order"
echo " <noisy> show line being executed"
echo " <additional> additional params to be passed (up to 3)"
exit 0
fi
if [[ ! -f $1 ]] ; then
echo "Can NOT find $1 - Aborting"
exit 1
fi
if [[ $(which $2 | grep "no $2") ]] ; then
echo "Can NOT find $2 - Aborting"
exit 1
fi
NOISY=
EXTRAPARAMS=
for param in $3 $4 $5 $6; do
if [ $param ] ; then
case $param in
noisy )
NOISY=true ;;
* )
EXTRAPARAMS=$EXTRAPARAMS" "$param ;;
esac
else
break
fi
done
# read through input file and run script using params from file
while read -r line
do
if [[ $NOISY ]] ; then echo "$2 $line $EXTRAPARAMS" ; fi
if [[ $line ]] ; then $2 $line $EXTRAPARAMS ; fi
done < $1
exit 0