-
Notifications
You must be signed in to change notification settings - Fork 3
/
runall
executable file
·52 lines (45 loc) · 1.03 KB
/
runall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
# I think this is a poor man's xargs, I don't really remember.
#
# Author: metakirby5
if [[ "$#" -lt 3 || "$#" -gt 4 ]]; then
echo "Usage: $(basename "$0") [program] [base dir] [inputs] (done extension)"
exit 0
fi
program=$1
basedir="${2%/}/"
inputs=$3
ext=$4
if [[ ! -d "$basedir" ]]; then
echo "Base directory \"$basedir\" not a directory!"
error=1
fi
if [[ ! -f "$inputs" ]]; then
echo "Inputs \"$inputs\" not found!"
error=1
fi
if [[ "$error" ]]; then
echo "Exiting due to error(s)..."
exit $error
fi
while read -r line; do
file="$basedir$line"
if [[ ! -f "$file" ]]; then
echo "=== File \"$file\" not found! Skipping..."
elif [[ "$ext" && -f "$file$ext" ]]; then
echo "=== Completed file \"$file$ext\" found! Skipping..."
else
cmd="$program $file"
read -p "====== Run \"$cmd\"? [y/n]: " -n 1 run < /dev/tty
wait
echo
if [[ ! "$run" =~ [yY] ]]; then
echo "=== Skipped \"$cmd\"."
else
echo "=== Running \"$cmd\"..."
$cmd < /dev/tty
wait
fi
fi
done < $inputs
echo "All files run!"