aboutsummaryrefslogtreecommitdiff
path: root/bin/apf
blob: 733d67fc49881edb4930374ba6611a3b54cf8bc0 (plain) (blame)
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
#!/usr/bin/env bash
# Prepend arguments from a file to a command call
self=apf

# Give up completely if no BASH_VERSINFO (<2.0)
[ -n "$BASH_VERSINFO" ] || exit

# Require at least two arguments, give usage otherwise
if (($# < 2)) ; then
    printf >&2 '%s: Need an arguments file and a command\n' "$self"
    exit 2
fi

# First argument is the file containing the null-delimited arguments
argfile=$1
shift

# Read all the null-delimited arguments from the file
declare -a args
while IFS= read -rd '' arg ; do
    args[${#args[@]}]=$arg
done < "$argfile"

# Next argument is the command to run
cmd=$1
shift

# Run the command with the retrieved arguments first, then the rest of the
# command line as passed to the function
command "$cmd" "${args[@]}" "$@"