execute multiple statements in if-else


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting execute multiple statements in if-else
# 1  
Old 01-05-2011
Java execute multiple statements in if-else

how can we execute multiple statements in
else condition
i have
if[ condition ]
then
statement
else
statements
fi
in else condition i have multiple statements
but it executing only one statement
is there any way to execute multiple statements
# 2  
Old 01-05-2011
What Operating System?
What Shell?
What's in the script?

In a normal Bourne-type shell (like ksh, bash or a Posix shell) there should be no problem UNLESS the statements themselves start a new Shell or cause the current shell to exit.
# 3  
Old 01-05-2011
Please post your code, it is likely not the if then else causing the problem
# 4  
Old 01-05-2011
@ALL


have a text file abc.txt as shown below
##################### text file begins####################
MONTH_20100801_1_IN.txt 2310 1042 0
MONTH_20100803_1_IN.txt 0708 708 0
MONTH_20100804_1_IN.txt 023 023 0
Number of agencies didnt send the file=0
sum of reject files= 0
MONTH_20100802_1.txt
MONTH_20100802_1_IN.txt
MONTH_20100805_1_IN.TXT
####################### end #########################
i need to run a script based on the values of those 2 lines
Number of agencies didnt send the file=0
sum of reject files= 0
if they both are zero i hav to run a script

######### for only one statement ...i wrote
grep 'Number of agencies didnt send the file=0' abc.txt
RC=$?
if [$RC -ne 0]
####some message
else
#### run script
fi
################################
i wann to worte like this if both the statements are zero....

if i put another grep statement ...it only reads the grep statement and exits
it wont run the statements below that......

its shell scripting
# 5  
Old 01-05-2011
I guess that this post is a paraphrase of this post by the same O/P:
https://www.unix.com/shell-programmin...p-command.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One Line Command how to use pipe statements to execute and comment on multiple possible outcomes

Hello Forum, I'm looking to expand the following command: INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server") Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

Using multiple 'for' statements

Hello, I am new to scripting and I am trying to write a simple script that creates users and adds their passwords from two files; one a user list file and another a password list file. For example, I have two files already. $ cat file1 andy stephane aby paul $ cat file2 123 234... (4 Replies)
Discussion started by: FemoTheDon
4 Replies

3. UNIX for Dummies Questions & Answers

Multiple if statements

exmaple: file1 and file2 has 1 bit if then exit else send out email fi if then exit else send out email fi it exits the 1st if. did not continue with my 2nd if. thanks in advanced. Please use CODE tags are suggested on every page when you post an item in... (7 Replies)
Discussion started by: lawsongeek
7 Replies

4. Shell Programming and Scripting

Multiple while statements?

I'm working on a script for class as a final project. We have to ask for values (city, state, zip) five times, but the state can only be MI, IN, IL, or OH. I'm trying to do this with a while loop inside of a while loop, but I have no idea how to do it properly. Here's what I have so far: ... (3 Replies)
Discussion started by: nickzourdos
3 Replies

5. Shell Programming and Scripting

Multiple if Statements

Hi All, I need to check for 3 conditions and if all the 3 are not satified need to say that services are not running.... is the below code correct. #********** Check to see if Service 1 is still running************** if then echo "$datetimestamp: Service1 is not running" >>... (4 Replies)
Discussion started by: ch33ry
4 Replies

6. Shell Programming and Scripting

How to execute a no of SELECT COUNT(*) statements using a loop

HI Unix Gurus, I have a number of SELECT count(*) statements in an input file and I want to execute it using a shell script but one by one using loop in script.... How can I do this..... (7 Replies)
Discussion started by: ustechie
7 Replies

7. Shell Programming and Scripting

Running multiple if statements

Hi, Hav automated a process, and it is working fine. for first process alone status = ` ps -ef |grep a ` if then echo " Success" > temp/logfile else echo " Failure" > temp/logfile fi Now I hav to write script to automated some 2 process and then send mail using cron.. ... (5 Replies)
Discussion started by: NehaKrish
5 Replies

8. Shell Programming and Scripting

How do I execute multiple statements within If then else

Please help me. I have been doing this for several hours. Here is the code if then echo a b c d >> file.txt echo 1111 >> file.txt fi The reason I want the two echo is because I want these statements printed on multiple lines. I keep getting error . First it tells me... (2 Replies)
Discussion started by: asemota
2 Replies

9. Shell Programming and Scripting

multiple 'if' statements out of array

I want to do multiple comparisons on a series of numbers from an array: I send the numbers in file1 through want to print out some info from file2 based on some conditions. The syntax just isn't correct??? awk ' NR==FNR{ a=$0 next ... (2 Replies)
Discussion started by: dcfargo
2 Replies

10. Shell Programming and Scripting

multiple conditions in if statements

Hi all, I'm confused about the proper syntax for multi-conditional if then statements. I'm trying to set limitations on info input on the command line.. i.e. if ] ;then $x=$vr1 else print "You have entered an invalid option." Can someone please clue me in on what is wrong with my syntax;... (3 Replies)
Discussion started by: tim mauger
3 Replies
Login or Register to Ask a Question