UCSF-Costello-Lab / LG3_Pipeline

The original LG3 pipeline
https://github.com/UCSF-Costello-Lab/LG3_Pipeline
0 stars 0 forks source link

bin/lg3-status: ShellCheck issues #150

Open HenrikBengtsson opened 3 years ago

HenrikBengtsson commented 3 years ago
$ make check_sh
* Validating shell scripts
shellcheck -x bin/lg3*

In bin/lg3-status line 2:
source "${LG3_HOME:?}/scripts/utils.sh"
       ^-- SC1090: Can't follow non-constant source. Use a directive to specify location.

In bin/lg3-status line 181:
                    MESS=$(ls -sh "${OUT}" | cut -d' ' -f1)
                                               ^-------------^ SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

In bin/lg3-status line 182:
                    MESS2=$(ls -sh "${OUT}" | cut -d' ' -f1)
                                                ^-------------^ SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

In bin/lg3-status line 214:
            for _file in ${WORKDIR}/${ID}.${RECAL_BAM_EXT}.*insert_size_metrics
                                     ^--------^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .
                                                ^---^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .
                                                      ^--------------^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .

In bin/lg3-status line 231:
            for _file in ${WORKDIR}/${ID}.${RECAL_BAM_EXT}.*insert_size_metrics
                             ^--------^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .
                                        ^---^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .
                                              ^--------------^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .

In bin/lg3-status line 492:
            NPDF=$(ls -1 ${WORKDIR}/${PATIENT},*.pdf 2> /dev/null | wc -l)
                       ^-- SC2012: Use find instead of ls to better handle non-alphanumeric filenames.
                             ^--------^ SC2086: Double quote to prevent globbing and word splitting.
                                        ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
            NPDF=$(ls -1 "${WORKDIR}"/"${PATIENT}",*.pdf 2> /dev/null | wc -l)

In bin/lg3-status line 493:
            NRDS=$(ls -1 ${WORKDIR}/${PATIENT},*.rds 2> /dev/null | wc -l)
                       ^-- SC2012: Use find instead of ls to better handle non-alphanumeric filenames.
                             ^--------^ SC2086: Double quote to prevent globbing and word splitting.
                                        ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
            NRDS=$(ls -1 "${WORKDIR}"/"${PATIENT}",*.rds 2> /dev/null | wc -l)

For more information:
  https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source....
  https://www.shellcheck.net/wiki/SC2012 -- Use find instead of ls to better ...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
HenrikBengtsson commented 3 years ago

I've fixed these issues in the develop (sic!) branch.

ivan108 commented 3 years ago

stat --printf="%s" produces different output compared to ls -sh Test:

$ stat --printf="%s" lg3-status
14998(base)
$ ls -sh lg3-status
15K lg3-status
HenrikBengtsson commented 3 years ago

Interesting, I cannot reproduce that (base) suffix;

On TIPCC:

[henrik@cclc01 ~/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin]$ pwd
/home/henrik/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin
[henrik@cclc01 ~/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin]$ size=$(stat --printf="%s" lg3-status)
[henrik@cclc01 ~/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin]$ echo "size='$size'"
size='14841'
[henrik@cclc01 ~/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin]$ which stat
/usr/bin/stat
[henrik@cclc01 ~/repositories/UCSF-CostelloLab/LG3_Pipeline-develop/bin]$ stat --version | head -1
stat (GNU coreutils) 8.4

On C4:

[henrik@c4-dev3 bin]$ pwd
/c4/home/henrik/repositories/UCSF-CostelloLab/LG3_Pipeline/bin
[henrik@c4-dev3 bin]$ size=$(stat --printf="%s" lg3-status)
[henrik@c4-dev3 bin]$ echo "size='$size'"
size='14841'

[henrik@c4-dev3 bin]$ which stat
/usr/bin/stat
[henrik@c4-dev3 bin]$ stat --version | head -1
stat (GNU coreutils) 8.22

Are you running some other version of stat?

ivan108 commented 3 years ago

On C4

[bin] $ which stat
/usr/bin/stat
[bin] $ size=$(stat --printf="%s" lg3-status)
[bin] $ echo $size
14998

The (base) suffix comes from anaconda... So it works as it supposed to, but what I want is "human" format (15K), looks nicer..

[bin]$ size=$(ls -sh lg3-status)
[bin]$ echo $size
15K lg3-status
HenrikBengtsson commented 3 years ago

... I want is "human" format (15K), looks nicer..

How critical is that? In order to get that, one needs to depend on also numfmt as in:

size=$(numfmt --to=si $(stat --printf="%s" lg3-status))
echo "size=${size}"
#> size=15K

PS. Note that ls -sh may not safe for other reasons too, e.g. one probably needs to use ls -1 -sh to handle "too many" files.