vendredi 6 décembre 2019

Bash script only works when variable is assigned incorrectly

So the script I'm working on has some secret tests I check it against, 20% of the tests pass when I have the first line of code below uncommented

noArgs = "false" <=== This line

If I change the the code to the either following then the original 20% start to fail, and the other 80% pass

#noArgs = "false" <=== commented out

noArgs="false" <=== properly set

If anyone has any idea what could be going wrong, or what the secret tests might be checking, I would be extremely grateful. (The script is supposed to compare output from running an .args file on a program to output from a .out file)

noArgs = "false"

for word in $(cat "$1"); do

  tmpfile=$(mktemp -t)

  if [ -f "$word.args" ]; then
    noArgs="false"
    "$2" $(cat $word.args) > $tmpfile
  else
    noArgs="true"
    "$2" > $tmpfile
  fi

  diff $word.out $tmpfile > /dev/null

  if [ $? -ne 0 ];
  then
    echo Args: 
    if [ $noArgs = "false" ]; then
      cat $word.args 
    fi
    echo Expected: 
    cat $word.out 
    echo Actual: 
    cat $tmpfile
  fi

  rm $tmpfile
done

Aucun commentaire:

Enregistrer un commentaire