Problem in executing For loop....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in executing For loop....
# 1  
Old 04-20-2011
Problem in executing For loop....

Hi frnds

I trying to execute the following ksh,
Code:
#!/bin/ksh
file=$OBS_APP_PATH/config/com/uhg/obs/inbound/configs/ServiceFeeDetail.xml
inputFileDir=$OBS_APP_PATH/config/com/uhg/obs/inbound/configs/
echo $file
echo $cntWrd
if[ -a $inputFileDir/ServiceFee*.xml ]
then
	echo "Inside IF"
	for i in 'ls -t1 $inputFileDir/ServiceFee*.xml'
		do
		  echo "Inside for loop"
		done
fi

Im getting the following error msg,

Code:
/obs/tst/app/scripts> ksh parsingIf.ksh
/obs/tst/app/config/com/uhg/obs/inbound/configs/ServiceFeeDetail.xml

: not found [No such file or directory]onfig/com/uhg/obs/inbound/configs/
: not found [No such file or directory]
Inside IF
' unexpectedh: line 8: syntax error at line 10: `do

Please help... Tnx in advance...

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 04-20-2011 at 04:54 AM.. Reason: code tags
# 2  
Old 04-20-2011
One issue with your if statment. A "space" is missing

Code:
if[ -a $inputFileDir/ServiceFee*.xml ]

change to

Code:
if [ -a $inputFileDir/ServiceFee*.xml ]

regards,
Ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 04-20-2011
Still not working...

I gave space even then im getting errors....

Code:
/obs/tst/app/scripts> ksh parsingIf.ksh
/obs/tst/app/config/com/uhg/obs/inbound/configs/ServiceFeeDetail.xml
' unexpectedh: line 4: syntax error at line 9: `do

# 4  
Old 04-20-2011
Also, from the code I think it should be like this.

Code:
#!/bin/ksh
file=~/test/ServiceFeeDetail.xml
inputFileDir=~/test
echo $file
echo $cntWrd
if [ -a $inputFileDir/ServiceFee*.xml ]
then
   echo "Inside IF"
   for i in `ls -t1 $inputFileDir/ServiceFee*.xml`
   do
     echo "Inside for loop"
   done
fi

Change done in for loop. Not single quotes, though single quotes also works but functionality differs.

regards,
Ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 04-20-2011
Couple of points..
Code:
#!/bin/ksh
file="${OBS_APP_PATH}/config/com/uhg/obs/inbound/configs/ServiceFeeDetail.xml" # Use variables within ${..} so it expands correctly
inputFileDir="${OBS_APP_PATH}/config/com/uhg/obs/inbound/configs/"
echo $file
echo $cntWrd
if [ -e "$inputFileDir/ServiceFee*.xml" ] # not sure what -a test checks, its an AND operator.If your looking for existance of a file then use -e
then
	echo "Inside IF"
	for i in `ls -t1 $inputFileDir/ServiceFee*.xml` # use backticks ` not single quotes '
	do
		echo "Inside for loop"
	done
fi

This User Gave Thanks to michaelrozar17 For This Post:
# 6  
Old 04-20-2011
Thanks for the replies friends..

But still im getting the same error message.. Even the IF stmt is not getting executed.... Smilie duuno where the problem is!!
# 7  
Old 04-20-2011
May be there are some control characters present.
Try removing those or rewrite the script without doing a copy-paste.
you have the ksh shell right? and which OS?

regards,
Ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing passing and executing select statement in loop

Hi, i want to do the following: Grep the following kind of strings for the 15digit ID which is stored in filename1: "14:06:51.396 INFO BMCREMEDYSD INPUT-ACTION Failed to retrieve Remedy Incident Modification record: 000000000039047 org.apache.axis2.AxisFault: Read timed out - complete... (9 Replies)
Discussion started by: Khushbu
9 Replies

2. Shell Programming and Scripting

Help with executing awk and While loop

Hi All, I have a file say, sample.txt Source Name: xxx Department|Revenue 1001|3252 1002|3345 I am using the above file in one of my script. I need to read from Line 3 of the above the file and do some process. My script has a code: awk 'NR > 2' sample.txt | while read Dep; do... (9 Replies)
Discussion started by: machomaddy
9 Replies

3. Shell Programming and Scripting

having problem while executing the script

Hi i am getting stuck while executing the script in the below line .Please help me out if ;then Name=`grep -i $Size $FILE|awk '{print $(NF-1),$NF}' |head -1` else Name="$Nam" fi (3 Replies)
Discussion started by: soumyamishra
3 Replies

4. Shell Programming and Scripting

cd command not executing in if else loop

Hi, I am executing below script s1=`pwd` s2=/space if then echo "done" else echo "mistake" cd /tmp fi I am not able to migrate to /tmp directory if the condition is not true.However mistake is being printed.Means cd command is not working here.All other commands except cd are... (3 Replies)
Discussion started by: d8011
3 Replies

5. Shell Programming and Scripting

error executing script in a while loop

Im unable to run scripts when i read each script thru a while loop. Is this way of execution thru while loop is wrong or is there any error in the script. I get the following error msg and i use ksh. ./vftest.ksh: ./add.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT: not found ... (7 Replies)
Discussion started by: michaelrozar17
7 Replies

6. Shell Programming and Scripting

Problem executing a script

Hi Friends, When I try to execute one of my script script1.shl, I am getting the error message as "/tmp/sh1871978.13: cannot create" . I could not find the specified sh* file in the /tmp directory and I also checked the disk space of /tmp and it is only 60% filled. Please help me on... (5 Replies)
Discussion started by: mr_manii
5 Replies

7. Shell Programming and Scripting

ssh and executing a for loop

Hi all, I am trying to run a script which is expected to do: on the remote machine, There are two directories /export/home/abc1,/export/home/abc2 i am trying to do, ssh SERVERNAME "for i in `ls -l /export/home/abc*|awk '{print $9}'`; do cd $i; ls -l; done" But its not working ,iam... (11 Replies)
Discussion started by: Jartan
11 Replies

8. Shell Programming and Scripting

Script not executing second loop

I have a server that receives backup files from several servers. Each server has its own directory to scp their files into, some of the files are received as .tar files and need to be compressed before being dumped. When the scp of the tar file is complete a file named 'flag' is also sent to... (2 Replies)
Discussion started by: thumper
2 Replies

9. Shell Programming and Scripting

Print out loop index on the console after executing each sybase DB query

Hello Guys, Well, using shell script, I'm doing loop on DB query as below: isql -Usa -Ptest -I /opt/sybase/interfaces << EOF use testdb go declare @i int select @i = 1 while(@i <= 5) begin Insert into TEST values (@i,"Test","TestDesc") select @i = @i + 1 end go EOF The Issue... (2 Replies)
Discussion started by: Alaeddin
2 Replies

10. Shell Programming and Scripting

Problem executing nohup

I am trying to submit background jobs using the nohup command on a client system where my session is running under a "master shell" (BASH). If I try to nohup the actual job (ie: nohup MYJOB.BAT > MYJOB.LOG 2>&1 &) the command will fail with a return code of 126 and a "permission denied" message.... (0 Replies)
Discussion started by: christyw
0 Replies
Login or Register to Ask a Question