blob: b6ee36d463da0d8f42356d29eeb9f49f40d887a5 (
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
31
32
33
34
|
#!/bin/sh
# Run a program with args read from standard input, prompted if from term
if [ "$#" -eq 0 ] ; then
printf >&2 'ap: Need at least one argument (command name)\n'
exit 2
fi
# Get the command name and shift it off
cmd=$1
shift
# Iterate through the remaining args; it's legal for there to be none, but in
# that case the user may as well just have invoked the command directly
for arg ; do
# If this is the first iteration, clear the params away (we grabbed them in
# the for statement)
if [ -z "$reset" ] ; then
set --
reset=1
fi
# If stdin is a terminal, prompt with the name of the argument
if [ -t 0 ] ; then
printf '%s: ' "$arg"
fi
# Note that a whitespace or even empty argument is allowed
IFS= read -r val
set -- "$@" "$val"
done
# Execute the command with the given parameters
exec "$cmd" "$@"
|