[Solved] Nested If

I am having a problem with a nested if. I am sure I am overlooking something. I check for the existence of $Pidfl3 and it exists, o this condition I then want to check for the existence of a next file and remove it. The first if is executed, but on the second if I get test: argument expected.

My Code

-->

        if [ -f $Pidfl3 ]
        then

          if [ -f $Pidfl ]
          then
            rm "$Pidfl" 
          fi
      
          if [ -f $Pidf2 ] 
          then
            rm "$Pidfl2" 
          fi

        else 


Can anybody help?

Check your script whether variable is assigned value before you use it in If

try double square braces

if [[ -f ${Pidfl3} ]]
then
  if [[ -f ${Pidfl} ]]
  then
    rm "${Pidfl}" 
  fi
  if [[ -f ${Pidf2} ]] 
  then
    rm "${Pidfl2}" 
  fi
else

Thank you

The double square brackets did the trick. As being new to scripting I am curious as to why?

Regards

Click here to know more about this.