forked from cirosantilli/linux-kernel-module-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheeval
More file actions
executable file
·27 lines (27 loc) · 724 Bytes
/
eeval
File metadata and controls
executable file
·27 lines (27 loc) · 724 Bytes
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
#!/usr/bin/env bash
# echo a command and eval it.
# Can also print the command to a file.
set -e
a=
while getopts a OPT; do
case "$OPT" in
a)
# Append to file instead of overwriting.
a=-a
;;
?)
exit 2
;;
esac
done
shift "$(($OPTIND - 1))"
cmd="$1"
outfile="${2:-/dev/null}"
mkdir -p "$(dirname "$outfile")"
echo "$cmd" | tee $a "$outfile"
# PIPESTATUS so that cmd="main_cmd | post_process" will return the status of cmd.
# Not POSIX.
# https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
# https://stackoverflow.com/questions/1221833/pipe-output-and-capture-exit-status-in-bash
eval "${cmd}; cmd_exit=\${PIPESTATUS[0]}"
exit "$cmd_exit"