How can I call function with parameter in bash?

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?

Upvotes: 0

Views: 54

Answers (1)

jotik
jotik

Reputation: 17900

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}"

Upvotes: 3

Related Questions