word too long error in script but not elsewhere...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting word too long error in script but not elsewhere...
# 1  
Old 01-21-2009
word too long error in script but not elsewhere...

Hi,

I have written a tcsh script that reads 3 directories, lists the files within them and continues on to evaluate each file independently. When I run the script, it gets to a certain directory that contains ~250 files, when you echo the directory, there are 4332 characters. So, when I use the echo command to list the files within that directory within the shell script, it produces a "word too long" error. The confusing thing is that when I run the commands directly in the shell (i.e., not through a script, type each command separately), I don't get the error. Is there anyone out there that can help me understand why the script fails, but running the commands directly in the shell does not result in an error?

Here is the list of the directories:
drwxr-sr-x 2 4096 Jan 21 10:37 SRS00001
drwxr-sr-x 2 4096 Jan 20 18:27 SRS00008
drwxr-sr-x 2 4096 Jan 21 11:04 SRS00009

Here is the section of the script (and output) that is failing:

set dlist = ();
set flist = ( `ls -d *` )
foreach f ($flist)
if ( -d $f ) set dlist = ( $dlist $f )
echo "dlist = $dlist"
------------------------------------------------------
output of the echo command for each iteration:
dlist = SRS00001
dlist = SRS00001 SRS00008
dlist = SRS00001 SRS00008 SRS00009

------------------------------------------------------
end

foreach d ( $dlist )
set flist = ( `find $d -name "*"` )
echo $flist
------------------------------------------------------
output of the echo command for each iteration:
SRS00001 SRS00001/IMG00000 SRS00001/IMG00001 ... SRS00001/IMG00049
SRS00008 SRS00008/IMG00000 SRS00008/IMG00001 ... SRS00008/IMG00024
SRS00009 SRS00009/IMG00000 SRS00009/IMG00001 ... SRS00009/IMG00247

------------------------------------------------------
end

As you can see, the last directory contains 248 images, resulting in an echo output of more than 4000 characters. I assume this is why I get the "word too long" error when I run the script, but why does it work when I manually type in the command in the shell?

I've been struggling with this for 2 days, and the script won't continue once it hits this directory, so I can't move on from this point. If anyone can help, it would be greatly appreciated. Thank you in advance!

nix
# 2  
Old 01-29-2009
The length of the available length on a command line varies depending on server memory and how the OS allocates resources to a process. It might be smaller in a shell script because memory has already been used for other things.

The typical work-around include (1) using find, (2) using shell pipes instead of glob-expansions to iterate over a list of files, (3) break up the glob into several subexpressions, such as "dotask [A-M]*" and then "dotask [N-Z]*", (4) use "xargs" which automatically breaks up long lines for you and runs the command enough times to use all command-line arguments.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

4. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

7. UNIX for Dummies Questions & Answers

Lines too long error

Hi Gurus, I have a big file having around 5000 lines. What I need to do is as below. $cat myfile aaaa bbbb ccc ddd ... I want the output to be as below: 'aaaa,'bbbb','cccc'.... For this I have written something like this code: vi sac.txt |nawk '{printf NR","}'>ss code: (2 Replies)
Discussion started by: thana
2 Replies

8. UNIX for Dummies Questions & Answers

word too long..problem while sourcing .cshrc

I am setting my PATH & LD_LIBRARY_PATH through .cshrc file while sourcing it on a old shell i am getting the error word too long .and the changes which i anm doing doesn't get updated . i am in a multi user environment so the only way to do the changes only for my shell is to do it that way. ... (1 Reply)
Discussion started by: mobydick
1 Replies

9. Solaris

word too long

Hello, When I try to run a shell script, It throws an error: $ ./SQLExecute.csh Word too long $ echo $CLASSPATH /u02/installs/calypso/calypsorel90000/jars/ $ echo $PATH... (7 Replies)
Discussion started by: panchpan
7 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question