Skip to content

Commit

Permalink
Merge pull request #3 from yarikoptic/enh-batch
Browse files Browse the repository at this point in the history
Add set -eu for guarding against errors, allow vars to be set in the environment
  • Loading branch information
neurolabusc authored Jun 23, 2017
2 parents cd1bfe7 + dc60a8e commit 01fd3df
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 01fd3df

Please sign in to comment.