Skip to content

Commit 7ec9615

Browse files
committed
lint & shellcheck scripts
1 parent af3c56c commit 7ec9615

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/pip-scripts/mk_env.sh

+31-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Copyright 2023 University of Birmingham, ResearchSoftwareGroup
44
# v0.1 by Simon Hartley
5-
#
65
# This program is free software: you can redistribute it and/or modify
76
# it under the terms of the GNU General Public License as published by
87
# the Free Software Foundation, either version 3 of the License, or
@@ -21,7 +20,8 @@ set -e
2120
# move to dir which this script is in:
2221
cd "${0%/*}"
2322

24-
export PROJECTROOT=$(pwd)
23+
PROJECTROOT=$(pwd)
24+
export PROJECTROOT
2525

2626
#colours for the terminal
2727
export RED='\e[38;5;198m'
@@ -194,24 +194,24 @@ function call_python() {
194194
#######################################
195195
function main() {
196196

197-
echo "odir->"${odir}
198-
echo "venv_name->"${venv_name}
199-
echo "save_freq->"${save_freq}
200-
echo "episode_max->"${episode_max}
201-
echo "del_env->"${del_env}
202-
echo "data_dir->"${data_dir}
203-
echo "steps_episode_max->"${steps_episode_max}
197+
echo "odir->${odir}"
198+
echo "venv_name->${venv_name}"
199+
echo "save_freq->${save_freq}"
200+
echo "episode_max->${episode_max}"
201+
echo "del_env->${del_env}"
202+
echo "data_dir->${data_dir}"
203+
echo "steps_episode_max->${steps_episode_max}"
204204

205205
# make the output folder
206206
if [[ ! -e $odir ]]; then
207-
mkdir -p ${odir}
207+
mkdir -p "${odir}"
208208
elif [[ ! -d $odir ]]; then
209209
echo "$odir already exists but is not a directory"
210210
exit_abnormal
211211
fi
212212

213213

214-
start=`date -u +%s`
214+
start='date -u +%s'
215215
Bask_load_modules_DeepCell
216216
ACTFILE="${PROJECTROOT}/apps/${venv_name}/bin/activate"
217217
if test -f "$ACTFILE"; then
@@ -226,12 +226,14 @@ function main() {
226226
# Do Python AI training and work
227227
call_python
228228
#***********************************************************************
229+
229230
if [[ $del_env =~ ^[Yy]$ ]]
230231
then
231232
# do rm of env folder
232233
clean
233234
fi;
234-
end=`date -u +%s`
235+
236+
end='date -u +%s'
235237

236238
runtime=$(date -u -d "0 $end seconds - $start seconds" +"%H:%M:%S")
237239

@@ -249,35 +251,35 @@ function main() {
249251

250252
while getopts ":o:s:e:p:d:r:" opt; do
251253
case $opt in
252-
o) odir=${OPTARG%/}; ;; # Remove trailing slash if present
254+
o) odir=${OPTARG%/}; ;; # Remove trailing slash if present
253255
e) venv_name=$OPTARG; ;;
254256
d) del_env=$OPTARG; ;;
255257
s)
256-
save_freq=$OPTARG # Set $checkpoints to specified value.
257-
re_isanum='^[0-9]+$' # Regex: match whole numbers only
258-
if ! [[ $save_freq =~ $re_isanum ]] ; then # if $checkpoints not whole:
258+
save_freq=$OPTARG # Set $checkpoints to specified value.
259+
re_isanum='^[0-9]+$' # Regex: match whole numbers only
260+
if ! [[ ${save_freq} =~ $re_isanum ]] ; then # if $checkpoints not whole:
259261
echo "Error: checkpoints must be a positive, whole number."
260-
exit_abnormal # Exit abnormally.
262+
exit_abnormal # Exit abnormally.
261263
fi; ;;
262264
p)
263-
episode_max=$OPTARG # Set $episode_max to specified value.
264-
re_isanum='^[0-9]+$' # Regex: match whole numbers only
265-
if ! [[ $episode_max =~ $re_isanum ]] ; then # if $episode_max not whole:
265+
episode_max=$OPTARG # Set $episode_max to specified value.
266+
re_isanum='^[0-9]+$' # Regex: match whole numbers only
267+
if ! [[ $episode_max =~ $re_isanum ]] ; then # if $episode_max not whole:
266268
echo "Error: episode_max must be a positive, whole number."
267-
exit_abnormal # Exit abnormally.
268-
elif [ $episode_max -eq "0" ]; then # If it's zero:
269+
exit_abnormal # Exit abnormally.
270+
elif [ "$episode_max" -eq "0" ]; then # If it's zero:
269271
echo "Error: episode_max must be greater than zero."
270-
exit_abnormal # Exit abnormally.
272+
exit_abnormal # Exit abnormally.
271273
fi; ;;
272274
r)
273-
steps_episode_max=$OPTARG # Set $steps_episode_max to specified value.
274-
re_isanum='^[0-9]+$' # Regex: match whole numbers only
275-
if ! [[ $steps_episode_max =~ $re_isanum ]] ; then # if $steps_episode_max not whole:
275+
steps_episode_max=$OPTARG # Set $steps_episode_max to specified value.
276+
re_isanum='^[0-9]+$' # Regex: match whole numbers only
277+
if ! [[ ${steps_episode_max} =~ $re_isanum ]] ; then # if $steps_episode_max not whole:
276278
echo "Error: steps_episode_max must be a positive, whole number."
277-
exit_abnormal # Exit abnormally.
278-
elif [ $steps_episode_max -eq "0" ]; then # If it's zero:
279+
exit_abnormal # Exit abnormally.
280+
elif [ "${steps_episode_max}" -eq "0" ]; then # If it's zero:
279281
echo "Error: steps_episode_max must be greater than zero."
280-
exit_abnormal # Exit abnormally.
282+
exit_abnormal # Exit abnormally.
281283
fi; ;;
282284
\?) echo "Error: invalid option: -$OPTARG"; exit_abnormal ;;
283285
:) echo "Error: option -$OPTARG requires an argument"; exit 1 ;;
@@ -293,5 +295,3 @@ main
293295
#######################################
294296

295297
exit 0 # Exit normally.
296-
297-

0 commit comments

Comments
 (0)