0

I have a function that I used for testing software. I have to call this function where the function have 2 parameters, that is currentSetName and failureDetected. This is the code:

#!/bin/bash

failureDetected=0 
nbOfAllTests=0
nbOfDetectedFailures=0`
currentSetName="fair"
count_input=1

removeFromCurrentSet(){
if [[("$1" == "good")]]
  then 
      #mv Partition/currentSet/* Partition/good_used
      echo "Hai good"

  elif [[("$1" == "fair")]]
  then
        if [[("$2" == "0")]]
        then
            #mv Partition/currentSet/* Partition/poor_used
            echo "hai fair poor_used"
        else 
            #mv Partition/currentSet/* Partition/good_used
            echo "hai fair good"
        fi
else

            #mv Partition/currentSet/* Partition/poor_used
            echo "jjj poor"

fi
}

removeFromCurrentSet currentSetName failureDetected

I use the code above but it's not work well. Can you help me for the problem? how can I call the function exactly?

0

1 Answer 1

3

You're incorrectly passing the arguments. Your original code is equivalent to

removeFromCurrentSet "currentSetName" "failureDetected"

just passing two strings, because currentSetName and failureDetected are not expanded. You need to expand the variables first using $.

To pass to the function the values of your variables try this instead:

removeFromCurrentSet "${currentSetName}" "${failureDetected}"
Sign up to request clarification or add additional context in comments.

2 Comments

Curly braces are only necessary if characters around the $ + variable expression would otherwise be interpreted as being part of it.
thank you @jotik it's solved my problem. sorry i haven't said before

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.