-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
60 lines (53 loc) · 1.12 KB
/
run.sh
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
53
54
55
56
57
58
59
# quiet COMMAND
# execute args as command but be quiet
# stdout and stderr are discarded
# exit code is propagated
#
# example
# if quiet diff A B ; then ...
# more or less equal to if diff -q A B but useful for command that
# doesn't suppor -q
#
bashfoo_require temp
quiet()
{
"$@" >/dev/null 2>&1
return $?
}
quiet_if_success()
{
#local tmp_file=`tmpfile_name quiet_if_success`
#cleanup_file "$tmp_file"
local quiet_if_success_quiet=0
if [ "$1" = "-q" ] ; then
quiet_if_success_quiet=1
shift
fi
local tmp_file="$(bashfoo.mktemp quiet-invocation)"
if ( "$@" ; ) > "$tmp_file" 2>&1 ; then
return 0
else
local r="$?"
if [ "$quiet_if_success_quiet" != 1 ] ; then
log_error "$@ execution failed (exit_code $r), log output follows"
fi
cat $tmp_file
return $r
fi
}
# run_in folder COMMAND
# execute args as command in specified folder
# exit code is propagated
#
# example
# run_in /etc cat passwd
#
run_in()
{
(
cd $1 ; shift
"$@"
return $?
)
return $?
}