Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set -eu for guarding against errors, allow vars to be set in the environment #3

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions batch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Fail if anything not planed to go wrong, goes wrong
set -eu

# Test if command exists.
exists() {
test -x "$(command -v "$1")"
Expand All @@ -8,14 +11,16 @@ exists() {
#exenam is executable
# we assume it is in the users path
# however, this could be set explicitly, e.g.
# exenam="/Users/rorden/Documents/cocoa/dcm2niix/console/dcm2niix"
exenam="dcm2niix"
# exenam="/Users/rorden/Documents/cocoa/dcm2niix/console/dcm2niix" batch.sh
exenam=${examnam:-dcm2niix}

#basedir is folder with "Ref" and "In" subfolders.
# we assume it is the same same folder as the script
# however, this could be set explicitly, e.g.
# basedir="/Users/rorden/dcm_qa"
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# basedir="/Users/rorden/dcm_qa" batch.sh
if [ -z ${basedir:-} ]; then
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi

#### no need to edit subsequent lines

Expand All @@ -31,17 +36,17 @@ exists $exenam ||
exit 1
}

if [ ! -d $indir ]; then
if [ ! -d "$indir" ]; then
echo "Error: Unable to find $indir"
exit 1
fi

if [ ! -d $refdir ]; then
if [ ! -d "$refdir" ]; then
echo "Error: Unable to find $refdir"
exit 1
fi

if [ ! -d $outdir ]; then
if [ ! -d "$outdir" ]; then
mkdir $outdir
fi

Expand Down