Error with for loop

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Error with for loop

There are two files abc_123.dat and abc_345.dat if at least one file exists then enter into the loop and remove file and exit.
In first iteration, deleting files successfully
but "else" statement executing after deleting files."else" should execute only if there is no file in the directory. For loop only to check abc*.dat file exists or not.

for i in $INPUTDIR/abc*.dat
        if  [ -f $i ]; then
                echo "delete data from table..."

ls -t abc*.dat | sort > ABC.lst

cat  ABC.lst | while read line
rm $line
                echo "File does not exist, exiting.."
return $exitcd

Moderator's Comments:
Mod Comment Please Use Code Tags. Check Out This Video to Learn How.

Last edited by Neo; 1 Week Ago at 01:43 AM..
# 2  
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Medium
Zero factorial is equal to zero.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting error in if loop

Hi All, while executing this code ,I'm gettign below Error if_test: line 3: #!/bin/bash if ; then echo "this is aginity;" elif ; then echo "this is informatica;" fi exit (3 Replies)
Discussion started by: netdbaind
3 Replies

2. Shell Programming and Scripting

Error in while loop

I have a file Table.out having table name like this Table_Emp Table_Exp Table_Fcr To show first 10 rows .. I' wrtng a script like this .. #!/bin/ksh cat /tmp/table.out|while read -r table vbar1 do <connect to db> then select * from $table limit 10; > /tmp/1.out done ... (3 Replies)
Discussion started by: netdbaind
3 Replies

3. Shell Programming and Scripting

Error with while loop

the program just prints all the command line arguments Getting error in the program error ./hellow: line 13: 0: command not found ./hellow: line 13: 0: command not found below is the program #!/bin/bash num=$# echo $num if then echo "No arguments are passed ." else ... (7 Replies)
Discussion started by: BHASKARREDDY006
7 Replies

4. Homework & Coursework Questions

Error in while loop

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am getting the following error while executing for while loo: count: command not found 2. Relevant... (4 Replies)
Discussion started by: manishdivs
4 Replies

5. Shell Programming and Scripting

Getting error in while loop

I am getting the following error msgs while executing for while loop: count: command not found do echo $count count = `expr $count + 1` done Please help me in creating and executing the above code. Many thanks in advance. (1 Reply)
Discussion started by: manishdivs
1 Replies

6. Shell Programming and Scripting

While loop error

I have a while loop in my script that works most times, but has generated an error once that has me a bit confused. I'm using ps to grab the runtime of a backgrounded command, and testing it to maintain the loop. If I test this on its own, I run into no problems, but during one use of the... (4 Replies)
Discussion started by: reid
4 Replies

7. Shell Programming and Scripting

Error Using an if Loop Within a While Loop

Hello All, I am having a problem with an “if loop” within a “while loop” in my Korn Shell program. The basic concept of the program is that it searches for the existence of a series of load files in a load directory, and once it finds one of these files, it begins the following process: · Creates... (4 Replies)
Discussion started by: jonesdk5
4 Replies

8. UNIX for Dummies Questions & Answers

error in for loop???

Hi, I get the following output 98 -1 98 0 ./get_AB04-time: line 79: ((: i< && 0 !=7 : syntax error: operand expected (error token is "&& 0 !=7 ") I have this part of code. Line 79 is the line of the for loop. echo ${OCCURRENCE} $i_START CASE=0; i_END=${i_START}... (4 Replies)
Discussion started by: f_o_555
4 Replies

9. Solaris

Error in while loop

Hi, Iam trying to add a while loop in my script in the below way which gets value from count file and checks if its not equal to 0.If yes then it shld echo me a message. while //count file has some number other than 0 do echo "count is not zero" done But iam getting this error:... (5 Replies)
Discussion started by: jyothi_wipro
5 Replies

10. Shell Programming and Scripting

while loop error

while read line do echo "read line is $line" done < $file where $file is file having following contents 1=one 2=two 3=three but above while loop is not able to print last line !! why ? (3 Replies)
Discussion started by: crackthehit007
3 Replies

Featured Tech Videos