Skip to content

Commit 3a914fc

Browse files
authored
Merge pull request #2130 from MIT-LCP/shellcheck
add shellcheck
2 parents 26da326 + cfb1818 commit 3a914fc

12 files changed

Lines changed: 146 additions & 116 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Lint all shell scripts in the repository with ShellCheck.
2+
# Picks up any *.sh file in the repo excluding .git
3+
name: ShellCheck
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
jobs:
12+
shellcheck:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v7
17+
- name: Run ShellCheck
18+
run: |
19+
find . -type f -name '*.sh' -not -path './.git/*' -print0 \
20+
| xargs -0 shellcheck

mimic-iii/buildmimic/duckdb/import_duckdb.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ elif [ -n "$3" ]; then
5858
die "Usage: ./import_duckdb.sh mimic_data_dir [output_db]"
5959
elif [ -s "$OUTFILE" ]; then
6060
yell "File \"$OUTFILE\" already exists."
61-
read -p "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: " yn
61+
printf "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: "
62+
read -r yn
6263
case $yn in
6364
[Yy]* ) ;; # OK
6465
[Nn]* ) exit;;

mimic-iii/buildmimic/postgres/create_mimic_user.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else
4141
fi
4242

4343
# check if SUDO is needed by checking if we can login with postgres without it
44-
err2=`psql postgres postgres -c "select 1;" 2>&1 >/dev/null`
44+
err2=$(psql postgres postgres -c "select 1;" 2>&1 >/dev/null)
4545

4646
if [[ $err2 == *"Peer authentication failed for user"* ]]; then
4747
# we need to call sudo every time for postgres

mimic-iii/concepts/make-concepts.sh

Lines changed: 72 additions & 71 deletions
Large diffs are not rendered by default.

mimic-iii/tests/md5.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
#!/bin/bash
12
# run in the folder:
23
# ./md5.sh checksum_md5_zipped.txt
34
# OR
45
# ./md5.sh checksum_md5_unzipped.txt
5-
while read p; do
6-
A="$(echo $p | cut -d' ' -f1)"
7-
B="$(echo $p | cut -d' ' -f2)"
8-
if [ ! -f $B ]
6+
while read -r p; do
7+
A="$(echo "$p" | cut -d' ' -f1)"
8+
B="$(echo "$p" | cut -d' ' -f2)"
9+
if [ ! -f "$B" ]
910
then
1011
echo "ERROR: $B does not exist"
1112
continue
1213
fi
13-
read C< <(md5 -q $B)
14-
echo $B $A = $C
15-
if [ $C != $A ]
14+
read -r C < <(md5 -q "$B")
15+
echo "$B" "$A" = "$C"
16+
if [ "$C" != "$A" ]
1617
then
1718
echo "ERROR: $B wrong md5"
1819
exit
1920
fi
20-
done <$1
21+
done < "$1"

mimic-iv-cxr/txt/chexpert/run_chexpert_on_files.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ fi
2222
sleep 2
2323

2424
# loop through each .csv file in the section folder
25-
for fn in `ls $REPORT_PATH`; do
26-
echo `date`: $fn
27-
fn_stem=`echo $fn | cut -d. -f 1`
25+
for fn in "$REPORT_PATH"/*; do
26+
fn=${fn##*/}
27+
echo "$(date): $fn"
28+
fn_stem=$(echo "$fn" | cut -d. -f 1)
2829
# run chexpert - must be run from chexpert folder
29-
python $CHEXPERT_PATH/label.py --verbose --reports_path $REPORT_PATH/$fn --output_path ${fn_stem}_labeled.csv --mention_phrases_dir $CHEXPERT_PATH/phrases/mention --unmention_phrases_dir $CHEXPERT_PATH/phrases/unmention --pre_negation_uncertainty_path $CHEXPERT_PATH/patterns/pre_negation_uncertainty.txt --negation_path $CHEXPERT_PATH/patterns/negation.txt --post_negation_uncertainty_path $CHEXPERT_PATH/patterns/post_negation_uncertainty.txt
30-
echo `date`: done!
30+
python "$CHEXPERT_PATH/label.py" --verbose --reports_path "$REPORT_PATH/$fn" --output_path "${fn_stem}_labeled.csv" --mention_phrases_dir "$CHEXPERT_PATH/phrases/mention" --unmention_phrases_dir "$CHEXPERT_PATH/phrases/unmention" --pre_negation_uncertainty_path "$CHEXPERT_PATH/patterns/pre_negation_uncertainty.txt" --negation_path "$CHEXPERT_PATH/patterns/negation.txt" --post_negation_uncertainty_path "$CHEXPERT_PATH/patterns/post_negation_uncertainty.txt"
31+
echo "$(date): done!"
3132
echo ''
3233
done

mimic-iv-cxr/txt/negbio/run_negbio.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ sleep 2
3232
# mimic_cxr_001.csv
3333
# mimic_cxr_002.csv
3434
# .. etc
35-
for fn in `ls $BASE_FOLDER`;
35+
for fn in "$BASE_FOLDER"/*;
3636
do
37+
fn=${fn##*/}
3738
echo "Looping through files with mimic_cxr_###.csv pattern."
3839
# validate it's a mimic_cxr sections file
3940
if [[ $fn =~ ^mimic_cxr_[0-9]+.csv$ ]];
@@ -44,18 +45,18 @@ do
4445
# all intermediate files will be saved in this folder
4546
export OUTPUT_DIR=${INPUT_FILE::-4}
4647

47-
echo $OUTPUT_DIR - running NegBio..
48-
python $NEGBIO_PATH/negbio/negbio_csv2bioc.py --output $OUTPUT_DIR/report $INPUT_FILE
49-
python $NEGBIO_PATH/negbio/negbio_pipeline.py section_split --pattern $NEGBIO_PATH/patterns/section_titles_cxr8.txt --output $OUTPUT_DIR/sections $OUTPUT_DIR/report/* --workers=6
50-
python $NEGBIO_PATH/negbio/negbio_pipeline.py ssplit --output $OUTPUT_DIR/ssplit $OUTPUT_DIR/sections/* --workers=6
51-
python $NEGBIO_PATH/negbio/negbio_pipeline.py parse --output $OUTPUT_DIR/parse $OUTPUT_DIR/ssplit/* --workers=6
52-
python $NEGBIO_PATH/negbio/negbio_pipeline.py ptb2ud --output $OUTPUT_DIR/ud $OUTPUT_DIR/parse/* --workers=6
53-
python $NEGBIO_PATH/negbio/negbio_pipeline.py dner_regex --phrases_file $NEGBIO_PATH/patterns/chexpert_phrases.yml --output $OUTPUT_DIR/dner $OUTPUT_DIR/ud/* --suffix=.chexpert-regex.xml --workers=6 --overwrite
54-
python $NEGBIO_PATH/negbio/negbio_pipeline.py neg2 --output $OUTPUT_DIR/neg --pre-negation-uncertainty-patterns $NEGBIO_PATH/patterns/chexpert_pre_negation_uncertainty.yml --neg-patterns $NEGBIO_PATH/patterns/neg_patterns2.yml --post-negation-uncertainty-patterns $NEGBIO_PATH/patterns/post_negation_uncertainty.yml --neg-regex-patterns $NEGBIO_PATH/patterns/neg_regex_patterns.yml --uncertainty-regex-patterns $NEGBIO_PATH/patterns/uncertainty_regex_patterns.yml $OUTPUT_DIR/dner/* --workers=6
48+
echo "$OUTPUT_DIR" - running NegBio..
49+
python "$NEGBIO_PATH/negbio/negbio_csv2bioc.py" --output "$OUTPUT_DIR/report" "$INPUT_FILE"
50+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" section_split --pattern "$NEGBIO_PATH/patterns/section_titles_cxr8.txt" --output "$OUTPUT_DIR/sections" "$OUTPUT_DIR"/report/* --workers=6
51+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" ssplit --output "$OUTPUT_DIR/ssplit" "$OUTPUT_DIR"/sections/* --workers=6
52+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" parse --output "$OUTPUT_DIR/parse" "$OUTPUT_DIR"/ssplit/* --workers=6
53+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" ptb2ud --output "$OUTPUT_DIR/ud" "$OUTPUT_DIR"/parse/* --workers=6
54+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" dner_regex --phrases_file "$NEGBIO_PATH/patterns/chexpert_phrases.yml" --output "$OUTPUT_DIR/dner" "$OUTPUT_DIR"/ud/* --suffix=.chexpert-regex.xml --workers=6 --overwrite
55+
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" neg2 --output "$OUTPUT_DIR/neg" --pre-negation-uncertainty-patterns "$NEGBIO_PATH/patterns/chexpert_pre_negation_uncertainty.yml" --neg-patterns "$NEGBIO_PATH/patterns/neg_patterns2.yml" --post-negation-uncertainty-patterns "$NEGBIO_PATH/patterns/post_negation_uncertainty.yml" --neg-regex-patterns "$NEGBIO_PATH/patterns/neg_regex_patterns.yml" --uncertainty-regex-patterns "$NEGBIO_PATH/patterns/uncertainty_regex_patterns.yml" "$OUTPUT_DIR"/dner/* --workers=6
5556

5657
# ultimate filename we save the labels to
5758
export OUTPUT_LABELS=$OUTPUT_DIR/${fn::-4}_labels.csv
58-
python $NEGBIO_PATH/negbio/ext/chexpert_collect_labels.py --phrases_file $NEGBIO_PATH/patterns/chexpert_phrases.yml --output $OUTPUT_LABELS $OUTPUT_DIR/neg/*
59+
python "$NEGBIO_PATH/negbio/ext/chexpert_collect_labels.py" --phrases_file "$NEGBIO_PATH/patterns/chexpert_phrases.yml" --output "$OUTPUT_LABELS" "$OUTPUT_DIR"/neg/*
5960
fi
6061
done
6162
echo "Done looping through files."

mimic-iv-ed/buildmimic/duckdb/import_duckdb.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ elif [ -n "$3" ]; then
5858
die "Usage: ./import_duckdb.sh mimic_data_dir [output_db]"
5959
elif [ -s "$OUTFILE" ]; then
6060
yell "File \"$OUTFILE\" already exists."
61-
read -p "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: " yn
61+
printf "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: "
62+
read -r yn
6263
case $yn in
6364
[Yy]* ) ;; # OK
6465
[Nn]* ) exit;;

mimic-iv-note/buildmimic/duckdb/import_duckdb.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ elif [ -n "$3" ]; then
5858
die "Usage: ./import_duckdb.sh mimic_data_dir [output_db]"
5959
elif [ -s "$OUTFILE" ]; then
6060
yell "File \"$OUTFILE\" already exists."
61-
read -p "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: " yn
61+
printf "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: "
62+
read -r yn
6263
case $yn in
6364
[Yy]* ) ;; # OK
6465
[Nn]* ) exit;;

mimic-iv/buildmimic/duckdb/import_duckdb.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ elif [ -n "$3" ]; then
5858
die "Usage: ./import_duckdb.sh mimic_data_dir [output_db]"
5959
elif [ -s "$OUTFILE" ]; then
6060
yell "File \"$OUTFILE\" already exists."
61-
read -p "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: " yn
61+
printf "Continue? (y/d/n) 'y' continues, 'd' deletes original file, 'n' stops: "
62+
read -r yn
6263
case $yn in
6364
[Yy]* ) ;; # OK
6465
[Nn]* ) exit;;

0 commit comments

Comments
 (0)