-
Notifications
You must be signed in to change notification settings - Fork 0
/
wap
executable file
·52 lines (40 loc) · 689 Bytes
/
wap
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
set -e
. functions
function usage {
cat <<END
Write standard output of a successful command to the same file sent to its standard input.
Usage:
$0 [<options>] <file> <command> [<arg> ...]
Options:
--help, -h
Display this help
END
exit 2
}
while [[ $# -gt 0 ]]; do
case $1 in
--help | -h)
usage
;;
--)
shift
break
;;
-*)
error "Unknown option: $1"
;;
*)
break
;;
esac
done
file=$1
shift || usage
[[ $# -gt 0 ]] || usage
[[ -e $file ]] || error "Target file not found"
[[ -f $file ]] || error "Target file not regular"
[[ -w $file ]] || error "Target file not writable"
tmp_file; tmp=$TMP_FILE
run "$@" < "$file" > "$tmp"
cp "$tmp" "$file"