Amber icon indicating copy to clipboard operation
Amber copied to clipboard

Shellcheck wrap variables

Open Mte90 opened this issue 1 year ago • 2 comments

Taking as example the date_compare.ab test we have this issues:

In /tmp/amber-sc-tests/date_compare.ab.sh line 9:
    if [ $(
         ^-- SC2046 (warning): Quote this to prevent word splitting.


In /tmp/amber-sc-tests/date_compare.ab.sh line 11:
        echo $?
             ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.


In /tmp/amber-sc-tests/date_compare.ab.sh line 15:
    if [ $(
         ^-- SC2046 (warning): Quote this to prevent word splitting.


In /tmp/amber-sc-tests/date_compare.ab.sh line 17:
        echo $?
             ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.


In /tmp/amber-sc-tests/date_compare.ab.sh line 23:
    if [ ${utc} != 0 ]; then
         ^----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    if [ "${utc}" != 0 ]; then


In /tmp/amber-sc-tests/date_compare.ab.sh line 49:
    if [ $(
         ^-- SC2046 (warning): Quote this to prevent word splitting.


In /tmp/amber-sc-tests/date_compare.ab.sh line 53:
        date_posix__0_v0 "" "" ${utc}
                               ^----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        date_posix__0_v0 "" "" "${utc}"


In /tmp/amber-sc-tests/date_compare.ab.sh line 58:
    date_posix__0_v0 "%s" "${date_a}" ${utc}
                                      ^----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    date_posix__0_v0 "%s" "${date_a}" "${utc}"


In /tmp/amber-sc-tests/date_compare.ab.sh line 66:
    date_posix__0_v0 "%s" "${date_b}" ${utc}
                                      ^----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    date_posix__0_v0 "%s" "${date_b}" "${utc}"


In /tmp/amber-sc-tests/date_compare.ab.sh line 74:
    if [ $(echo ${timestamp_a} '>' ${timestamp_b} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
         ^-- SC2046 (warning): Quote this to prevent word splitting.
                ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                   ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    if [ $(echo "${timestamp_a}" '>' "${timestamp_b}" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then


In /tmp/amber-sc-tests/date_compare.ab.sh line 78:
    if [ $(echo ${timestamp_a} '==' ${timestamp_b} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
         ^-- SC2046 (warning): Quote this to prevent word splitting.
                ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                    ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    if [ $(echo "${timestamp_a}" '==' "${timestamp_b}" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then


In /tmp/amber-sc-tests/date_compare.ab.sh line 82:
    if [ $(echo ${timestamp_a} '<' ${timestamp_b} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
         ^-- SC2046 (warning): Quote this to prevent word splitting.
                ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                   ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    if [ $(echo "${timestamp_a}" '<' "${timestamp_b}" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then


In /tmp/amber-sc-tests/date_compare.ab.sh line 94:
if [ $(echo $(echo "$__AF_date_compare3_v0__4_16" '==' $(echo '-' 1 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') '&&' $(echo "$__AF_date_compare3_v0__4_60" '==' 1 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
     ^-- SC2046 (warning): Quote this to prevent word splitting.
            ^-- SC2046 (warning): Quote this to prevent word splitting.
                                                       ^-- SC2046 (warning): Quote this to prevent word splitting.
                                                                                                                                                                 ^-- SC2046 (warning): Quote this to prevent word splitting.

For more information:
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
  https://www.shellcheck.net/wiki/SC2319 -- This $? refers to a condition, no...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

We fix some of those issues (also in other tests) but I am still working on some of the warning here.

Mte90 avatar Jul 30 '24 14:07 Mte90

Now is just:

In ./date_compare.ab.sh line 11:
        echo $?
             ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.


In ./date_compare.ab.sh line 17:
        echo $?
             ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.


In ./date_compare.ab.sh line 94:
if [ "$(echo "$(echo ""$__AF_date_compare3_v0__4_16"" '==' "$(echo "" '-' "1" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" '&&' "$(echo ""$__AF_date_compare3_v0__4_60"" '==' "1" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" != 0 ]; then
                       ^--------------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                       ^--------------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                                                                                       ^--------------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                                                                                                                                                       ^--------------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
if [ "$(echo "$(echo """$__AF_date_compare3_v0__4_16""" '==' "$(echo "" '-' "1" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" '&&' "$(echo """$__AF_date_compare3_v0__4_60""" '==' "1" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" != 0 ]; then

For more information:
  https://www.shellcheck.net/wiki/SC2027 -- The surrounding quotes actually u...
  https://www.shellcheck.net/wiki/SC2319 -- This $? refers to a condition, no...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

We are working for the 2 issues in 2 different tickets, so it will be their turn soon.

Mte90 avatar Jul 30 '24 14:07 Mte90

@Mte90 to fix the shell check warnings I propose you to go get the minimal Amber code needed, generate bash from it and then try to understand the root cause of this warning. Perhaps the function calls are not wrapped in double quotes or maybe just the variables?

Ph0enixKM avatar Aug 06 '24 09:08 Ph0enixKM