jeudi 28 mars 2019

If statement condition fails and skips straight to the else part

I'm reading in a file and school comes in forms of number 2,3,4,5 and each corresponds to a specific school like HS, Middle school etc. But my condition always fails and causes it to go to the else statements.

#!bin/bash
OLDIFS=$IFS
IFS=","

while read  First_Name Last_Name Grade Student_Id school
do  

if [ $school == 2 ]
    then
    School=$(echo $school | sed -e 's/2/HS/g')
    echo "$NAME"."$last_Name" "$NAME" "$last_Name" "$Grade"thGrade 
    "$Student_Id" "$School"

  elif [ $school == 3 ]
    then
    School=$(echo $school | sed -e 's/3/MI/g')
    echo "$NAME"."$last_Name" "$NAME" "$last_Name" Class"..." 
    "$Student_Id" "$School"

  elif [ $school == 4 ]
     then
    School=$(echo $school | sed -e 's/4/MO/g')
    echo "$NAME"."$last_Name" "$NAME" "$last_Name" Class"..." 
    "$Student_Id" "$School"

  else
    School=$(echo $school | sed -e 's/5/K/g')
    echo "$NAME"."$last_Name" "$NAME" "$last_Name" Class"..." 
    "$Student_Id" "$School"

fi


done < $1   
IFS=$OLDIFS

The condition fails and it skips to the else statement.

Aucun commentaire:

Enregistrer un commentaire