Bash script if condition not executing

issue is with .txt files

PLEASE get accustomed to post the full picture! How else do you expect prople to analyse the problem and eventually help you?

  • What's your shell (the shebang won't work!)?
  • Where is the part of the code BEFORE the elif ?
  • What's the contents of $psent80
  • Which echo is executed ?

And, in fact, the if statement is NOT skipped; it's the then branch that is not taken.

if statement is not calling .txt file due to \r in .txt file

$psent75 is tested but not set anywhere.

Added data in the script

when I change if condition as below

if [ "$psent80" != "n" ];

it is working

To test I did executed the script again , as I have got an email for that value , this time I should not get an email and the script should give echo part

But this logic is not happening

again and again the email is generated with out going to below block

else
                                echo "Mail aready sent for 75%"
                        fi

I'd propose you get your act together, post the entire script, all (consistently named!) variables' contents and (!) expected ("n" or "no"?) contents, and complete error messages/descriptions.

this small thing took out my whole time

ok this is the answer finally

tr -d '\r' < filewithcarriagereturns > filewithoutcarriagereturns

fix the .txt files

Moderator comments were removed during original forum migration.
2 Likes