Skip to content

Check rear *.sh scripts for lonely words #549

@jsmeix

Description

@jsmeix

This is an enhancement proposal for better syntax check of the scripts.

Currently only "bash -n" is run for the *.sh scripts which cannot detect many problems like misspelled variables, functions, commands and many more.

My personal reason is that I did misspell a variable (that was never commited to rear upstream) and I found it only by debugging a failure during my own testing.

I don't know a good bash syntax checker.

In particular for rear we would neeed a bash syntax checker that can check the overall syntax of all *.sh scripts.

Therefore as a first attempt to do a little better syntax check I like to propse hereby to check for words that exist only once in all *.sh scripts.

What I did right now as a very first proof of concept in a rear source directory:

$ rm /tmp/rear_all_scripts.sh

$ find . -name '*.sh' | xargs cat >>/tmp/rear_all_scripts.sh

$ cat /tmp/rear_all_scripts.sh | grep -v '^[[:space:]]*#' | tr -c -s '[:space:][:alnum:]_-' ' ' | tr -s '[:space:]' '\n' | sort | uniq -c | grep '^[[:space:]]*1 [[:alpha:]]' | cut -b9- >/tmp/rear_all_scripts.lonely_words

$ for w in $( cat /tmp/rear_all_scripts.lonely_words ) ; do echo $w ; find . -name '*.sh' | xargs egrep -h "[^[:alpha:]]$w[^[:alpha:]]|^$w[^[:alpha:]]" ; echo ------------------------------------------------------------------------------------------------------------------ ; done | grep -v '^[[:space:]]*#' | less

This way I found 1159 lonely words in all *.sh scripts.

Now I use my own brain and imagination to view that long "less" output for suspicious cases of lonely words that could be real bugs...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions