-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathniinote
executable file
·40 lines (34 loc) · 1.14 KB
/
niinote
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
#!/usr/bin/env bash
set -euo pipefail
#
# run 3dNotes to annotate output ($1) of a cmd ($@)
#
# 20200110WF: init
cmd=$(basename $0)
[ $# -lt 2 ] && \
echo "USAGE: $cmd output cmd\nEXAMPLE: $cmd betted.nii.gz bet input.nii.gz betted.nii.gz" && \
exit 1
export AFNI_NO_OBLIQUE_WARNING="YES" # 3dNotes likes to complain. silence it
output="$1"; shift
# ext used if there are spaces in output name
! [[ "$output" =~ nii(.gz)$ ]] && echo "unknown extention. need nii or nii.gz!" >&2 && exit 1
ext=$BASH_REMATCH
#eval "$@" || exit $?
arg="$(printf "%q " "$@")"
# arg="$(printf "%q " "$*")" # all a giant quote
eval "$arg" || exit $?
arg="$*"
[ ! -r "$output" ] &&
echo "# ERROR: no expected output '$output'! but successfully ran cmd $arg" >&2 &&
exit 1
# 3dNotes does not like writting to a prefix with spaces
MOVEBACK=""
if [[ "$(basename "$output")" =~ " " ]]; then
echo "# WARNING! '$output' has a space! WHY? moving to and from temp for 3dNotes" >&2
MOVEBACK="$output"
output=$(mktemp /tmp/XXXXX.$ext)
mv "$MOVEBACK" "$output"
fi
3dNotes -h "'${arg//\'/\"}'" "$output" || exit $?
[ -n "$MOVEBACK" ] && mv "$output" "$MOVEBACK"
exit 0