How to treat the error code : name file too long
Hi team,
A problem with a bash shell. Here is the context : for rpt in `ls myfiles*.txt` do instruction 1 $rpt instruction 2 $rpt ... instruction n $rpt done When to much files an error message : name file too long appears. How to treat correctly that problem ? Any information will be appreciate. Thank's in advance. mland. |
Is the error message translated? I would expect something more like "argument list too long".
First thing (although it won't help you with this exact problem - just a general tip) - you don't need to do this: Code:
for rpt in `ls myfiles*.txt` The good news is, the shell will expand glob patterns for you, so just do this instead: Code:
for rpt in myfiles*.txt Code:
find . -name "myfiles*.txt" -maxdepth 1 -type f |while read rpt [/CODE]#!/bin/bash counter=0 seq 1 5 | while read n; do let counter+=1 echo "random number $counter is $RANDOM" done echo "after loop, value of counter is: $counter"[/CODE] I hope that helps. |
A complement to this topic : how to add a sort clause to the list of files ?
Thank's you matthewg42 for replys.
It was a great help. A complement to this topic : how to add a sort clause to the list of files ? Thank's in advance. mland. |
If you're piping the files into a while loop, just insert a sort in the pipeline:
Code:
find . -name "myfiles*.txt" -maxdepth 1 -type f | sort | while read rpt |
Thank's again,
a complement to this topic, The command above : find . -name "myfiles.txt" -maxdepth 1 -type f | while read rpt return a list of filenames "myfiles.txt" with the path. I try the command above to return the list of filenames without the path find . -name "myfiles.txt" -maxdepth 1 -type f -printf %f | while read rpt But it nothing is return. What is wrong and how to do it ? Thank's in advance for a return mland. |
Code:
for fpath in `find . -name "myfiles*.txt" -maxdepth 1 -type f` |
All times are GMT -5. The time now is 09:58 AM. |