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

Add shellcheck support and robustify present shell scripts #5294

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Commits on Feb 16, 2024

  1. Configuration menu
    Copy the full SHA
    ac438ef View commit details
    Browse the repository at this point in the history
  2. [DATALAD RUNCMD] Apply recommended by shellcheck fixes to run

    === Do not change lines below ===
    {
     "chain": [
      "f724281d8f3cd1dc4f3538186d91fdf0bc8cf997"
     ],
     "cmd": "shellcheck -f diff run | patch -p1",
     "exit": 0,
     "extra_inputs": [],
     "inputs": [],
     "outputs": [],
     "pwd": "."
    }
    ^^^ Do not change lines above ^^^
    yarikoptic committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    91976cb View commit details
    Browse the repository at this point in the history
  3. Add an ignore for shellcheck with TODO and possible "fixes"

    It is not clear from the code what was envisioned "exactly". But as given it is
    analogous to "${*:2}" if what was really wanted is to get a single string with
    all args from 2nd concatenated.
    
    Here are the helpers used here:
    
        ❯ cat /tmp/show
        #!/bin/bash
    
        args=${@:2}
        echo "$args"
        /home/yoh/bin/printargs "$args"
    
        qargs="${@:2}"  # just quoted to pacify shellcheck
        /home/yoh/bin/printargs "$qargs"
    
        qargs="${*:2}"  # quoted and * instead of @ to pacify shellcheck
        /home/yoh/bin/printargs "$qargs"
    
        corrected_args=( "${@:2}" )
        echo "$corrected_args"
        /home/yoh/bin/printargs "$corrected_args"
        # as array
        /home/yoh/bin/printargs "${corrected_args[@]}"
        changes on filesystem:
         run | 6 ++++++
    
        ❯ cat ~/bin/printargs
        #!/bin/bash
    
        for a in "$@"; do
        echo ">$a<"
        done
    
    which would produce following output
    
        ❯ bash -x /tmp/show 1 "2 2" 3 4 5
        + args='2 2 3 4 5'
        + echo '2 2 3 4 5'
        2 2 3 4 5
        + /home/yoh/bin/printargs '2 2 3 4 5'
        >2 2 3 4 5<
        + qargs='2 2 3 4 5'
        + /home/yoh/bin/printargs '2 2 3 4 5'
        >2 2 3 4 5<
        + qargs='2 2 3 4 5'
        + /home/yoh/bin/printargs '2 2 3 4 5'
        >2 2 3 4 5<
        + corrected_args=("${@:2}")
        + echo '2 2'
        2 2
        + /home/yoh/bin/printargs '2 2'
        >2 2<
        + /home/yoh/bin/printargs '2 2' 3 4 5
        >2 2<
        >3<
        >4<
        >5<
    
    and shellcheck would report following issues on the helper:
    
    	❯ shellcheck /tmp/show
    
    	In /tmp/show line 3:
    	args=${@:2}
    		 ^----^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
    
    	In /tmp/show line 7:
    	qargs="${@:2}"  # just quoted to pacify shellcheck
    		  ^------^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
    
    	In /tmp/show line 14:
    	echo "$corrected_args"
    		  ^-------------^ SC2128 (warning): Expanding an array without an index only gives the first element.
    
    	In /tmp/show line 15:
    	/home/yoh/bin/printargs "$corrected_args"
    							 ^-------------^ SC2128 (warning): Expanding an array without an index only gives the first element.
    
    	For more information:
    	  https://www.shellcheck.net/wiki/SC2124 -- Assigning an array to a string! A...
    	  https://www.shellcheck.net/wiki/SC2128 -- Expanding an array without an ind...
    yarikoptic committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    beed5fd View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b477d0e View commit details
    Browse the repository at this point in the history