Skip to content

[Proposal]: Use ShellCheck for the Linux/Mac script #11

@YisusChrist

Description

@YisusChrist

It is not always mandatory, but using some external tools such as ShellCheck can help to find potential bugs and risks in the shell code that is produced by the Instl script.

This is the report generated for the username/reponame script:

[Line 1:](javascript:setPosition(1, 1))
################################################################################
^-- [SC2148](https://www.shellcheck.net/wiki/SC2148) (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
 
[Line 230:](javascript:setPosition(230, 10))
  alias "${1}$2"="$3"
         ^-- [SC2139](https://www.shellcheck.net/wiki/SC2139) (warning): This expands when defined, not when used. Consider escaping.
 
[Line 242:](javascript:setPosition(242, 19))
  alias -p | grep $1 | cut -d'=' -f1 | awk -F"$1" '{print $2; }'
                  ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([2])), apply [all SC2086](javascript:applyFixCode(2086)))
  alias -p | grep "$1" | cut -d'=' -f1 | awk -F"$1" '{print $2; }'
 
[Line 265:](javascript:setPosition(265, 10))
mkdir -p $binaryLocation
         ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([3])), apply [all SC2086](javascript:applyFixCode(2086)))
mkdir -p "$binaryLocation"
 
[Line 274:](javascript:setPosition(274, 10))
mkdir -p $installLocation
         ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([4])), apply [all SC2086](javascript:applyFixCode(2086)))
mkdir -p "$installLocation"
 
[Line 313:](javascript:setPosition(313, 16))
getReleaseArgs=$curlOpts
               ^-- [SC2128](https://www.shellcheck.net/wiki/SC2128) (warning): Expanding an array without an index only gives the first element.
 
[Line 315:](javascript:setPosition(315, 21))
releaseJSON="$(curl ${getReleaseArgs[@]})"
                    ^-- [SC2068](https://www.shellcheck.net/wiki/SC2068) (error): Double quote array expansions to avoid re-splitting elements.
 
[Line 340:](javascript:setPosition(340, 6))
if [ $arch == "x86_64" ]; then
     ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([7])), apply [all SC2086](javascript:applyFixCode(2086)))
if [ "$arch" == "x86_64" ]; then
 
[Line 342:](javascript:setPosition(342, 8))
elif [ $arch == "i386" ] || [ $arch == "i686" ]; then
       ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.
                              ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([8,9])), apply [all SC2086](javascript:applyFixCode(2086)))
elif [ "$arch" == "i386" ] || [ "$arch" == "i686" ]; then
 
[Line 366:](javascript:setPosition(366, 22))
  currentOsAliases+=(${linux[@]})
                     ^-- [SC2206](https://www.shellcheck.net/wiki/SC2206) (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
 
[Line 368:](javascript:setPosition(368, 22))
  currentOsAliases+=(${darwin[@]})
                     ^-- [SC2206](https://www.shellcheck.net/wiki/SC2206) (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
 
[Line 415:](javascript:setPosition(415, 8))
  if [ $score -gt $maxScore ]; then
       ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.
                  ^-- [SC2086](https://www.shellcheck.net/wiki/SC2086) (info): Double quote to prevent globbing and word splitting.

Did you mean: ([apply this](javascript:applyFixIndex([12,13])), apply [all SC2086](javascript:applyFixCode(2086)))
  if [ "$score" -gt "$maxScore" ]; then
 
[Line 429:](javascript:setPosition(429, 19))
downloadAssetArgs=$curlOpts
                  ^-- [SC2128](https://www.shellcheck.net/wiki/SC2128) (warning): Expanding an array without an index only gives the first element.
 
[Line 431:](javascript:setPosition(431, 6))
curl ${downloadAssetArgs[@]}
     ^-- [SC2068](https://www.shellcheck.net/wiki/SC2068) (error): Double quote array expansions to avoid re-splitting elements.

As I said, It is not always mandatory but the team should definitely take a look at these warnings and errors reported that may help to make the script more safe.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions