Bash script if condition not executing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script if condition not executing
# 1  
Old 03-27-2017
Bash script if condition not executing

issue is with .txt files

Last edited by anil529; 03-27-2017 at 11:11 PM.. Reason: Added CODE tags.
# 2  
Old 03-27-2017
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.

Last edited by RudiC; 03-27-2017 at 08:13 AM.. Reason: rephrased
# 3  
Old 03-27-2017
if statement is not calling .txt file due to \r in .txt file

Last edited by anil529; 03-27-2017 at 11:12 PM.. Reason: Replaced icode tags with code tags and formatted code... see a missing `fi'
# 4  
Old 03-27-2017
$psent75 is tested but not set anywhere.
# 5  
Old 03-27-2017
Quote:
Originally Posted by RudiC
$psent75 is tested but not set anywhere.
Added data in the script

when I change if condition as below
Code:
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

Code:
else
                                echo "Mail aready sent for 75%"
                        fi


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-27-2017 at 03:14 PM.. Reason: Added CODE tags.
# 6  
Old 03-27-2017
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.
# 7  
Old 03-27-2017
this small thing took out my whole time

ok this is the answer finally

Code:
tr -d '\r' < filewithcarriagereturns > filewithoutcarriagereturns

fix the .txt files

Last edited by Don Cragun; 03-28-2017 at 12:21 AM.. Reason: Add CODE tags again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Condition in bash script

I want get from user and pass these parameters to bash script. script should copy files in user home directory. FYI: each file might be exist or not, might be one of them exist or four of them. Here is my script, it always copy file1 and seems only one of them execute! #!/bin/bash for... (6 Replies)
Discussion started by: indeed_1
6 Replies

2. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable sed.sh regexp sed.sh "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies

3. Shell Programming and Scripting

Creating a condition on a bash script

I wrote a code to find codons in a DNA string. The only problem I have is how do I make the code only work for a file with DNA. This means the file only has the characters a,c,g,t and no white space characters. (3 Replies)
Discussion started by: germany1517
3 Replies

4. Shell Programming and Scripting

Need Multiple checks inside if condition in a bash shell script

Hi, I need to perform the untar and rm operation if the file found is a .tar and does not have test.tar or hello.tar as the file names. Below is the loop to check the same. for tf in *.tar do if ] then found=1 ... (1 Reply)
Discussion started by: mohtashims
1 Replies

5. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

6. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

Hi All, Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out. Regards Rahul ---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
Discussion started by: rahulkalra9
2 Replies

7. Shell Programming and Scripting

Bash script errors when executing

I'm working on a script that will search through a directory for MKV files and remux them to MP4. I found a few other scripts around the net that do this, but they all have limitations that don't always get the job done. The main limitation I've found is that most scripts look for the video track... (2 Replies)
Discussion started by: rayne127
2 Replies

8. Programming

if condition in bash

Hi, I have meaning to include an if condition statement in my code to check the directory for existing output files and if its existing i want the program to delete it before doing the succeeding command. i just dont know the correct syntax for it. thanks much guys, this forum has indeed been very... (4 Replies)
Discussion started by: ida1215
4 Replies

9. Shell Programming and Scripting

[bash] Executing script that is held in a variable

Hi, I'm building an installation system that uses separate data files that contain the individual characteristics of each package. Within the data file, I would like to incorporate a section that contains a bash script that is loaded into an array which is then redirected to bash to be... (13 Replies)
Discussion started by: ASGR
13 Replies

10. UNIX for Dummies Questions & Answers

Specified Ksh but executing in bash

Hi, I am a new bie to unix shell programming. I have specified ksh as the first line in my script but when executed it complains. *********** Script=test******************** #!/usr/bin/ksh echo hello print -p 123 ************************************ ++++++++ Execution... (7 Replies)
Discussion started by: akhilnagpal
7 Replies
Login or Register to Ask a Question