Limit of ls command in for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Limit of ls command in for loop
# 1  
Old 04-05-2010
Limit of ls command in for loop

I am using the code below to list all the Errors files from the directory in the for loop. When the number of files are less then 6000 then it's works fine but if it more than that then for loop fails.

Code:
for file in `ls $ERR_DIR/PPL_Prov_Engine_Error_*`
do
memrecno=`cut -f2 -d'|' $file` || checkReturn $STEP $LINENO $?
done

Please suggest.

Last edited by pludi; 04-06-2010 at 01:07 PM.. Reason: code tags, please...
# 2  
Old 04-05-2010
Use:
Code:
for file in "$ERR_DIR"/PPL_Prov_Engine_Error_*

Not only will it not choke on a command line length limit, it will properly handle pathnames with IFS characters (by default, space/tab/newline).

Regards,
Alister
# 3  
Old 04-06-2010
Hi Alister,

Your code will put all the files in $file variable and actully I want to read one file at a time and do some processing on that file and read second file so on.

So if the loop run 100 times then my file variable should have 100 value in it.

Please suggest.
# 4  
Old 04-06-2010
Did you even try it?
# 5  
Old 04-06-2010
yes I have tried it .
# 6  
Old 04-06-2010
You seem to be under the impression that my code somehow dumps all filenames into $file and iterates once; that's mistaken. It iterates over each filename, one at a time. If that's not what occured when you used it, then you are doing something wrong. If you'd like some help with it, post the code that you tried and any errors generated.

The for loop I shared above is the simplest, safest, most efficient solution to your problem (using ls to generate a list of filenames in a directory is never needed, can generate erroneous results after field splitting occurs, and is constrained by system command line length limits).
# 7  
Old 04-06-2010
Thanks it is working now.
I have done syntax error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Limit on number of pipes after long-running command?

I'm trying to create a minimal, crude keylogger for X using only a shell script. I was quickly stumped: Why do these two commands entered in a terminal emulator produce output when I type... $ xinput test 6 | grep press $ xinput test 6 | awk '{print $3}' ...but this command produces no... (13 Replies)
Discussion started by: DevuanFan
13 Replies

2. Shell Programming and Scripting

While loop with limit counter

#!/usr/bin/ksh c=0 while ]; do echo /tmp/unex NOT found, iter : $c; ((c = $c + 1)); sleep 2; done so, the above counter doesn't work, already tried both -lt & -gt, and changed || to && so what am I missing? Thanks in advance (5 Replies)
Discussion started by: unexistance
5 Replies

3. Shell Programming and Scripting

While loop running after reaching limit

Hi frnds i am newbie in linux and trying to write a simple script for adding users.the problem is i am running a while loop under function and loop is running for 3 time more than limit.Here is my Script and output pls help me out : # CREATE N NO. OF USERS WITH PASSWORD IN SYSTEM #... (4 Replies)
Discussion started by: Vaibhav.T
4 Replies

4. Cybersecurity

How to limit patchadd command to root user only?

How to limit patchadd command to root user only? I'm running a solaris 10 5/09 server, I have 2 users other than root. One being able to use the patchadd command and one is unable to do so. What I'm trying to do is to limit the patchadd command so that only root is able to run it. (7 Replies)
Discussion started by: ShouTenraku
7 Replies

5. Shell Programming and Scripting

Ignore the 255 character limit of command line

Hi I would just like to ask if there is a way for UNIX to ignore/overcome the 255 character limit of the command line? My problem is that I have a really long line of text from a file (300+ bytes) which i have to "echo" and process by adding commands like "sed" to the end of the line, like... (5 Replies)
Discussion started by: agentgrecko
5 Replies

6. UNIX for Dummies Questions & Answers

limit of command length

Hi! Can you please help me with one question? Does rexec command have some limitation of the length of the deliveded cmd? Thanks in advance, Anta (2 Replies)
Discussion started by: Anta
2 Replies

7. UNIX for Dummies Questions & Answers

Limit Unix command to user

Is it possible to limit a user account to only several commands. For security reasons, i would like for some users given accounts to only execute commands limited to them. If possible, how can it be done? tyvm. (1 Reply)
Discussion started by: coolphilboy
1 Replies

8. Shell Programming and Scripting

Is there a limit to mget command?

Hi All, I am using a csh ftp to get all the relevant files i need. When i reduce the number of file to 4 (which is aaa,bbb,ccc,ddd), the script manage to get all the files i need. But when i add "eee" to the mget command, it doesn;t seem to get any files at all. Is there a limit to how many... (0 Replies)
Discussion started by: Raynon
0 Replies

9. UNIX for Dummies Questions & Answers

Command line buffer limit?

Is there a limit (255 chars?) on the command line?? I'm trying to copy some generated java & class files from one dir to another and ID the old & new versions by: find . -name FFSFIXADminCallbackBean.java I then do a copy and paste of the source and target - $ cp -p source target It... (7 Replies)
Discussion started by: kornshellmaven
7 Replies

10. UNIX for Dummies Questions & Answers

Limit command

I have installed vnc on my computer but do not want every one to be able to incite a vncserver how can I limit users of the vncserver command to only a specifc group? (1 Reply)
Discussion started by: macdonto
1 Replies
Login or Register to Ask a Question