Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix as many existing ShellCheck reports as possible #470

Closed
lzaoral opened this issue Aug 25, 2022 · 6 comments
Closed

Fix as many existing ShellCheck reports as possible #470

lzaoral opened this issue Aug 25, 2022 · 6 comments
Labels
Milestone

Comments

@lzaoral
Copy link
Contributor

lzaoral commented Aug 25, 2022

Describe the bug

PR #469 added a ShellCheck linting on PRs with new changes. However, problems in already existing files are not reported (unless they are fixed). This issue tries to aggregate all such files.

List of affected shell scripts for commit 8f5f423

ShellCheck version: 8.0.0

--- ./contrib/guide/get_started/00-cleanup.sh ---
      1 SHELLCHECK_WARNING
--- ./contrib/guide/get_started/12-datadir-create.sh ---
      1 SHELLCHECK_WARNING
--- ./contrib/scripts/resetgnome ---
      7 SHELLCHECK_WARNING
--- ./contrib/template/.bash_profile ---
      2 SHELLCHECK_WARNING
--- ./contrib/template/.bashrc ---
      2 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/bar-defaults.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/bar-loads.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/bar-switch.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh ---
      6 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/foo-avail1.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/foo-avail2.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/foo-defaults.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/foo-loads.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/foo-switch.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/modavail.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/modversion.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/ompi-defaults.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/ompi-loads1.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/ompi-switch.sh ---
      1 SHELLCHECK_WARNING
--- ./doc/example/compiler-etc-dependencies/example-sessions/ompi-switch.sh.m431 ---
      3 SHELLCHECK_WARNING
--- ./doc/example/source-script-in-modulefile/bar-2.1/bar-setup.sh ---
      3 SHELLCHECK_WARNING
--- ./doc/example/source-script-in-modulefile/foo-1.2/foo-setup.sh ---
      3 SHELLCHECK_WARNING
--- ./init/bash.in ---
      9 SHELLCHECK_WARNING
--- ./init/bash_completion.in ---
     63 SHELLCHECK_WARNING
--- ./init/ksh.in ---
      9 SHELLCHECK_WARNING
--- ./init/profile.sh.in ---
      4 SHELLCHECK_WARNING
--- ./init/sh.in ---
      9 SHELLCHECK_WARNING
--- ./script/add.modules.in ---
     52 SHELLCHECK_WARNING
--- ./script/commit-msg ---
      3 SHELLCHECK_WARNING
--- ./script/envml ---
      1 SHELLCHECK_WARNING
--- ./script/mkroot ---
     13 SHELLCHECK_WARNING
--- ./script/mt ---
     12 SHELLCHECK_WARNING
--- ./script/pre-commit ---
      9 SHELLCHECK_WARNING
--- ./testsuite/bin/install_test_sh ---
     16 SHELLCHECK_WARNING
--- ./testsuite/cmd.exe ---
      1 SHELLCHECK_WARNING
--- ./testsuite/example/mini-sh-to-mod.sh ---
      1 SHELLCHECK_WARNING
--- ./testsuite/example/sh-to-mod.sh ---
     10 SHELLCHECK_WARNING
--- ./testsuite/home/.module/.target ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/coll1 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/coll2 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/coll3 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/coll4.target ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/coll6.target ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/default ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.module/infocmdexp ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.modules.save ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.modules.saveempty ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/.modules.savenull ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-hide-once-loaded-nuasked ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-0 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-1 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-2 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-3 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-4 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-5 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll-sticky-6 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll10 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll11 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll12 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll13 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll14 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll15 ---
      7 SHELLCHECK_WARNING
--- ./testsuite/home/coll16 ---
     11 SHELLCHECK_WARNING
--- ./testsuite/home/coll26 ---
      9 SHELLCHECK_WARNING
--- ./testsuite/home/coll27 ---
      5 SHELLCHECK_WARNING
--- ./testsuite/home/coll28 ---
      5 SHELLCHECK_WARNING
--- ./testsuite/home/coll29 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll30 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll31 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll32 ---
      3 SHELLCHECK_WARNING
--- ./testsuite/home/coll33 ---
      3 SHELLCHECK_WARNING
--- ./testsuite/home/coll39 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll5 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll7 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll8 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/coll9 ---
      1 SHELLCHECK_WARNING
--- ./testsuite/home/rcnomagic ---
      1 SHELLCHECK_WARNING
--- ./testsuite/systest ---
      3 SHELLCHECK_WARNING

I've tried to filter all unrelated files from this list but It's possible that some of them are not actual shell scrips.

EDIT: Remove ./script/mb since it's not a shell script.

@lzaoral lzaoral added the bug label Aug 25, 2022
@xdelaruelle
Copy link
Member

Thanks for this report. Could you please detail how shellcheck was run to obtain this report. Many files checked in the above report are modulefiles or module collection, not shell scripts.

@xdelaruelle
Copy link
Member

Never mind my previous comment. I have checked the whole repository and find the files to check with shellcheck:

script/add.modules.in
script/commit-msg
script/envml                                                                                             
script/mkroot                                                                                            
script/modulecmd.in                                                                                      
script/mt                                                                                                
script/pre-commit                                                                                        
configure                                                                                                
init/bash_completion.in
init/profile.sh.in
init/bash.in
init/sh.in
init/ksh.in
testsuite/systest1
testsuite/not_installed
testsuite/systest0
testsuite/mode
testsuite/systest
testsuite/systest2
testsuite/stty
testsuite/cmd.exe
testsuite/is_module_defined
testsuite/bin/install_test_sh
contrib/get_started/*.sh
file $(find doc/example/) | grep 'Bourne-Again'

I will take this opportunity to also remove unmaintained and (I think) deprecated scripts from repository:

contrib/template/.bashrc
contrib/template/README.dotfiles
contrib/template/.mailcap
contrib/template/.fvwm2rc
contrib/template/resetenv.conf
contrib/template/.logout
contrib/template/.mime.types
contrib/template/.cshrc
contrib/template/.bash_profile
contrib/template/.aliases
contrib/template/.login
contrib/scripts/resetenv
contrib/scripts/resetgnome

@xdelaruelle xdelaruelle added this to the 5.2 milestone Aug 26, 2022
@lzaoral
Copy link
Contributor Author

lzaoral commented Aug 26, 2022

Thank you, @xdelaruelle! I also went through the whole repository and I listed all text files that looked like shell scripts both to me and to ShellCheck. I've already started fixing some reports so I'll post a PR soon.

@xdelaruelle
Copy link
Member

On my side, I will create a new lint testsuite that will be callable with make testlint or script/mt lint. It will detect all the script shells in the repository and run shellcheck on all of that.

I will also check the Tcl scripts with Nagelfar through this testsuite.

lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Different shells support different features.  To give effective advice,
ShellCheck needs to know which shell your script is going to run on.

Related: https://www.shellcheck.net/wiki/SC2148
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Double quotes around $@ and ${array[@]}) prevent globbing and word splitting
of individual elements, while still expanding to multiple separate arguments.

Related: https://www.shellcheck.net/wiki/SC2068
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Bourne shells are very whitespace sensitive.  Adding or removing spaces can
drastically alter the meaning of a script.

Related: https://www.shellcheck.net/wiki/SC1035
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

-a and -o  in [ .. ] test expressions are not well defined, and can cause
incorrect results when arguments start with dashes or contain !.

Related: https://www.shellcheck.net/wiki/SC2166
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
These occurrences do not seem to cause any problems described below but
let's still fix it for the sake of consistency within this script.

According to ShellCheck's documentation:

ShellCheck noticed that you have used a variable as an array, but then assign
it a string.  array=foo is equivalent to array[0]=foo, and leaves the rest
of the elements unaffected.

Related: https://www.shellcheck.net/wiki/SC2178
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Use "$@" (with quotes) to prevent whitespace problems.  $* and ${array[*]},
unquoted, is subject to word splitting and globbing.

Related: https://www.shellcheck.net/wiki/SC2048
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
These occurrences do not cause any problems described below but it's better
to be verbose that we indeed want to access the first array element.

According to ShellCheck's documentation:

When referencing arrays, $myarray is equivalent to ${myarray[0]} --
it results in only the first of multiple elements.

Related: https://www.shellcheck.net/wiki/SC2128
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Arrays and $@ can contain multiple elements.  Simple variables contain only
one.  When assigning multiple elements to one element, the default behavior
depends on the shell (bash concatenates with spaces, zsh concatenates with
first char of IFS).

Related: https://www.shellcheck.net/wiki/SC2124
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

In the original code, the return value of mycmd in $(mycmd) is ignored,
and export will instead always return true.  This may prevent conditionals,
set -e and traps from working correctly.

Related: https://www.shellcheck.net/wiki/SC2155
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
Some variables, that were unquoted intentionally were converted to arrays.

According to ShellCheck's documentation:

Quoting variables prevents word splitting and glob expansion, and prevents
the script from breaking when input contains spaces, line feeds, glob
characters and such.

Related: https://www.shellcheck.net/wiki/SC2086
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

When command expansions are unquoted, word splitting and globbing will occur.
This often manifests itself by breaking when filenames contain spaces.

Related: https://www.shellcheck.net/wiki/SC2046
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

export takes a variable name, but ShellCheck has noticed that you give it
an expanded variable instead.  Remove $/${} for that, or use ${var?} to quiet.

Related: https://www.shellcheck.net/wiki/SC2163
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Different shells support different features.  To give effective advice,
ShellCheck needs to know which shell your script is going to run on.

Related: https://www.shellcheck.net/wiki/SC2148
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Double quotes around $@ and ${array[@]}) prevent globbing and word splitting
of individual elements, while still expanding to multiple separate arguments.

Related: https://www.shellcheck.net/wiki/SC2068
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Bourne shells are very whitespace sensitive.  Adding or removing spaces can
drastically alter the meaning of a script.

Related: https://www.shellcheck.net/wiki/SC1035
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

-a and -o  in [ .. ] test expressions are not well defined, and can cause
incorrect results when arguments start with dashes or contain !.

Related: https://www.shellcheck.net/wiki/SC2166
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
These occurrences do not seem to cause any problems described below but
let's still fix it for the sake of consistency within this script.

According to ShellCheck's documentation:

ShellCheck noticed that you have used a variable as an array, but then assign
it a string.  array=foo is equivalent to array[0]=foo, and leaves the rest
of the elements unaffected.

Related: https://www.shellcheck.net/wiki/SC2178
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Use "$@" (with quotes) to prevent whitespace problems.  $* and ${array[*]},
unquoted, is subject to word splitting and globbing.

Related: https://www.shellcheck.net/wiki/SC2048
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
These occurrences do not cause any problems described below but it's better
to be verbose that we indeed want to access the first array element.

According to ShellCheck's documentation:

When referencing arrays, $myarray is equivalent to ${myarray[0]} --
it results in only the first of multiple elements.

Related: https://www.shellcheck.net/wiki/SC2128
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

Arrays and $@ can contain multiple elements.  Simple variables contain only
one.  When assigning multiple elements to one element, the default behavior
depends on the shell (bash concatenates with spaces, zsh concatenates with
first char of IFS).

Related: https://www.shellcheck.net/wiki/SC2124
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

In the original code, the return value of mycmd in $(mycmd) is ignored,
and export will instead always return true.  This may prevent conditionals,
set -e and traps from working correctly.

Related: https://www.shellcheck.net/wiki/SC2155
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
Some variables, that were unquoted intentionally were converted to arrays.

According to ShellCheck's documentation:

Quoting variables prevents word splitting and glob expansion, and prevents
the script from breaking when input contains spaces, line feeds, glob
characters and such.

Related: https://www.shellcheck.net/wiki/SC2086
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

When command expansions are unquoted, word splitting and globbing will occur.
This often manifests itself by breaking when filenames contain spaces.

Related: https://www.shellcheck.net/wiki/SC2046
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

export takes a variable name, but ShellCheck has noticed that you give it
an expanded variable instead.  Remove $/${} for that, or use ${var?} to quiet.

Related: https://www.shellcheck.net/wiki/SC2163
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
Some variables, that were unquoted intentionally were converted to arrays.

According to ShellCheck's documentation:

Quoting variables prevents word splitting and glob expansion, and prevents
the script from breaking when input contains spaces, line feeds, glob
characters and such.

Related: https://www.shellcheck.net/wiki/SC2086
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

When command expansions are unquoted, word splitting and globbing will occur.
This often manifests itself by breaking when filenames contain spaces.

Related: https://www.shellcheck.net/wiki/SC2046
Related: cea-hpc#470
lzaoral added a commit to lzaoral/modules that referenced this issue Aug 31, 2022
According to ShellCheck's documentation:

export takes a variable name, but ShellCheck has noticed that you give it
an expanded variable instead.  Remove $/${} for that, or use ${var?} to quiet.

Related: https://www.shellcheck.net/wiki/SC2163
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Different shells support different features.  To give effective advice,
ShellCheck needs to know which shell your script is going to run on.

Related: https://www.shellcheck.net/wiki/SC2148
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Double quotes around $@ and ${array[@]}) prevent globbing and word splitting
of individual elements, while still expanding to multiple separate arguments.

Related: https://www.shellcheck.net/wiki/SC2068
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Bourne shells are very whitespace sensitive.  Adding or removing spaces can
drastically alter the meaning of a script.

Related: https://www.shellcheck.net/wiki/SC1035
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

-a and -o  in [ .. ] test expressions are not well defined, and can cause
incorrect results when arguments start with dashes or contain !.

Related: https://www.shellcheck.net/wiki/SC2166
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
These occurrences do not seem to cause any problems described below but
let's still fix it for the sake of consistency within this script.

According to ShellCheck's documentation:

ShellCheck noticed that you have used a variable as an array, but then assign
it a string.  array=foo is equivalent to array[0]=foo, and leaves the rest
of the elements unaffected.

Related: https://www.shellcheck.net/wiki/SC2178
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Use "$@" (with quotes) to prevent whitespace problems.  $* and ${array[*]},
unquoted, is subject to word splitting and globbing.

Related: https://www.shellcheck.net/wiki/SC2048
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
These occurrences do not cause any problems described below but it's better
to be verbose that we indeed want to access the first array element.

According to ShellCheck's documentation:

When referencing arrays, $myarray is equivalent to ${myarray[0]} --
it results in only the first of multiple elements.

Related: https://www.shellcheck.net/wiki/SC2128
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

In the original code, the return value of mycmd in $(mycmd) is ignored,
and export will instead always return true.  This may prevent conditionals,
set -e and traps from working correctly.

Related: https://www.shellcheck.net/wiki/SC2155
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
Some variables, that were unquoted intentionally were converted to arrays.

According to ShellCheck's documentation:

Quoting variables prevents word splitting and glob expansion, and prevents
the script from breaking when input contains spaces, line feeds, glob
characters and such.

Related: https://www.shellcheck.net/wiki/SC2086
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

When command expansions are unquoted, word splitting and globbing will occur.
This often manifests itself by breaking when filenames contain spaces.

Related: https://www.shellcheck.net/wiki/SC2046
Related: cea-hpc#470
xdelaruelle pushed a commit to lzaoral/modules that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

export takes a variable name, but ShellCheck has noticed that you give it
an expanded variable instead.  Remove $/${} for that, or use ${var?} to quiet.

Related: https://www.shellcheck.net/wiki/SC2163
Related: cea-hpc#470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Different shells support different features.  To give effective advice,
ShellCheck needs to know which shell your script is going to run on.

Related: https://www.shellcheck.net/wiki/SC2148
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Double quotes around $@ and ${array[@]}) prevent globbing and word splitting
of individual elements, while still expanding to multiple separate arguments.

Related: https://www.shellcheck.net/wiki/SC2068
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Bourne shells are very whitespace sensitive.  Adding or removing spaces can
drastically alter the meaning of a script.

Related: https://www.shellcheck.net/wiki/SC1035
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

-a and -o  in [ .. ] test expressions are not well defined, and can cause
incorrect results when arguments start with dashes or contain !.

Related: https://www.shellcheck.net/wiki/SC2166
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
These occurrences do not seem to cause any problems described below but
let's still fix it for the sake of consistency within this script.

According to ShellCheck's documentation:

ShellCheck noticed that you have used a variable as an array, but then assign
it a string.  array=foo is equivalent to array[0]=foo, and leaves the rest
of the elements unaffected.

Related: https://www.shellcheck.net/wiki/SC2178
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

Use "$@" (with quotes) to prevent whitespace problems.  $* and ${array[*]},
unquoted, is subject to word splitting and globbing.

Related: https://www.shellcheck.net/wiki/SC2048
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
These occurrences do not cause any problems described below but it's better
to be verbose that we indeed want to access the first array element.

According to ShellCheck's documentation:

When referencing arrays, $myarray is equivalent to ${myarray[0]} --
it results in only the first of multiple elements.

Related: https://www.shellcheck.net/wiki/SC2128
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

In the original code, the return value of mycmd in $(mycmd) is ignored,
and export will instead always return true.  This may prevent conditionals,
set -e and traps from working correctly.

Related: https://www.shellcheck.net/wiki/SC2155
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
Some variables, that were unquoted intentionally were converted to arrays.

According to ShellCheck's documentation:

Quoting variables prevents word splitting and glob expansion, and prevents
the script from breaking when input contains spaces, line feeds, glob
characters and such.

Related: https://www.shellcheck.net/wiki/SC2086
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

When command expansions are unquoted, word splitting and globbing will occur.
This often manifests itself by breaking when filenames contain spaces.

Related: https://www.shellcheck.net/wiki/SC2046
Related: #470
xdelaruelle pushed a commit that referenced this issue Sep 2, 2022
According to ShellCheck's documentation:

export takes a variable name, but ShellCheck has noticed that you give it
an expanded variable instead.  Remove $/${} for that, or use ${var?} to quiet.

Related: https://www.shellcheck.net/wiki/SC2163
Related: #470
xdelaruelle added a commit to xdelaruelle/modules that referenced this issue Sep 15, 2022
Make 'mt lint' pass with remaining shellcheck reports on sh, bash and
ksh scripts. Waiting for another contribution to fix the remaining
warnings and notices.

Related: cea-hpc#470
xdelaruelle added a commit that referenced this issue Sep 15, 2022
Make 'mt lint' pass with remaining shellcheck reports on sh, bash and
ksh scripts. Waiting for another contribution to fix the remaining
warnings and notices.

Related: #470
@lzaoral
Copy link
Contributor Author

lzaoral commented Oct 5, 2022

@xdelaruelle, thanks again for the fixes! I've not forgotten about this issue but, unfortunately, I don't know when I'll be able get to it again because right now I'm busy with finishing my thesis and other, more urgent, stuff related to RHEL.

@xdelaruelle
Copy link
Member

No problem @lzaoral. I am closing this issue, as the work achieved for next version (5.2) on this topic is already a good step forward.

But do not hesitate to send other pull requests on this topic when you will have more time. This is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants