Execution problem with IF statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem with IF statement
# 1  
Old 03-29-2010
Execution problem with IF statement

Hi,

I am trying to execute the below statment in my script.am getting the error as " syntax error near unexpected token 'else'. Is If statement is correct.

Code:
if [[ $q_dirs == 'q1' || $q_dirs == 'gf' || $q_dirs == 'tf' || $q_dirs == 'hi' || $q_dirs == 'ac' ]];
then
  if [[ $q_dirs == 'q1' || $q_dirs == 'gf' ]];
  then
    cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/$q_dirs/import-serv/
  else
    cdsgq_dir=`echo $q_dirs | sed 's/global//' | awk '{print}'|tr '[A-Z]' '[a-z]'`
    echo $cdsgq_dir 
    #cdsgq_dir=echo $q_dirs | sed 's/cdsglobal//' | awk '{print}' 
    cp $src_dir/import-serv/$cdsgq_dir*.txt  $tgt_dir/$q_dirs/import-serv/
  else
    cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/error_files/
  fi
fi

Any help is much appreciated

Thanks in advance

Last edited by Franklin52; 03-29-2010 at 06:18 AM.. Reason: Please indent your code and use code tags!
kirankumar
# 2  
Old 03-29-2010
check this syntax and correct ur code.

Code:
if condition
	then
		if condition
		then
			.....
			..
			do this
		else
			....
			..
			do this
		fi
	else
		...
		.....
		do this
	fi

# 3  
Old 03-29-2010
Quote:
Originally Posted by kirankumar
Hi,

I am trying to execute the below statment in my script.am getting the error as " syntax error near unexpected token 'else'. Is If statement is correct.

Code:
if [[ $q_dirs == 'q1' || $q_dirs == 'gf' || $q_dirs == 'tf' || $q_dirs == 'hi' || $q_dirs == 'ac' ]];
then
  if [[ $q_dirs == 'q1' || $q_dirs == 'gf' ]];
  then
    cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/$q_dirs/import-serv/
  else
    cdsgq_dir=`echo $q_dirs | sed 's/global//' | awk '{print}'|tr '[A-Z]' '[a-z]'`
    echo $cdsgq_dir 
    #cdsgq_dir=echo $q_dirs | sed 's/cdsglobal//' | awk '{print}' 
    cp $src_dir/import-serv/$cdsgq_dir*.txt  $tgt_dir/$q_dirs/import-serv/
  else
    cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/error_files/
  fi
fi

You have a second else statement !
Remove UUoC(s)
# 4  
Old 03-29-2010
Code:
case "$q_dirs" in
    q1|gf)    
            ...
            ;;
    tf|hi|ac)
           ...
           ;;
    *)    ....
           ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Sqlplus - Capture the sql statement about to run and execution status

Greetings Experts, I am on AIX using ksh. Created a unix script which generates the CREATE OR REPLACE VIEW ... and GRANT .. statements, which are placed in a single .txt file. Now I need to execute the contents in the file (there are around 300 view creation and grant statements) in Oracle and... (4 Replies)
Discussion started by: chill3chee
4 Replies

2. UNIX for Dummies Questions & Answers

Execution problem

How to search a pattern from multiple files... i used the command suppose the pattern name is xxx grep xxx (file1-o- file2-o- file3) Thanks in advance (4 Replies)
Discussion started by: ksakil
4 Replies

3. Shell Programming and Scripting

Execution problem

Hi, I have been trying to run a simple script CONFIG_FILE="/jay/check" . . . for i in `cat $CONFIG_FILE` do loc=`echo $i | cut -d "|" -f2` var=$(find $loc -mtime -1|wc -l) if then echo $loc has files older than 1 day fi done . . . (2 Replies)
Discussion started by: jayii
2 Replies

4. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

5. UNIX for Dummies Questions & Answers

execution problem

HI I am trying to check the status of port using command /code: netstat -an | grep port /Output: *.2009 *.* 0 0 65535 0 LISTEN what i am trying to do is i want to grep only status Wether the port is established/listen if so show ok else... (1 Reply)
Discussion started by: esumiba
1 Replies

6. UNIX for Dummies Questions & Answers

execution problem

Hi I am automating my few commands out of which one command is tail -f running.logs when i run this command it does not automatically exit and show prompt (#) what would i do so that it will exit out automatically after few seconds and move to the next command without using ... (4 Replies)
Discussion started by: esumiba
4 Replies

7. UNIX for Dummies Questions & Answers

execution problem

Hi i have a file in which there are three fields code: 919804199233 404911130003916 357266044991350F and now i want to add two more fields i.e. code: 919804199233 404911130003916 357266044991350F ms 123 how can i do it using command line and if have a file of 100... (8 Replies)
Discussion started by: esumiba
8 Replies

8. UNIX for Dummies Questions & Answers

execution problem

Hi i am using expect module and trying to login using following code. ssh 127.0.0.1 expect "word:" send "$password \n" kindly let me know the login script using expect module (1 Reply)
Discussion started by: esumiba
1 Replies

9. HP-UX

Reg: execution of tail statement in PUTTY

We are using PUTTY to connect to Remote Unix Server. When I run the following shell script statement, I do not get the desired output. tail -num test.txt > test.out here "num" is any number for example say as 2000. What happens is..test.out contains around 400 rows only out of 2000. It... (0 Replies)
Discussion started by: subbukns
0 Replies

10. UNIX for Dummies Questions & Answers

korn shellscript execution context - exit statement

Hi all, Could someone please explain to me the shell invocation process when running a script. How do I stop the shell from logging out when it reaches an exit statement in the script? if ; then echo 'Failed to copy ${FILE}.fmx to ${J2_HOME}/dev/rsc' ... (3 Replies)
Discussion started by: richgi
3 Replies
Login or Register to Ask a Question