Sunny Dubey wrote:
> how come the followind doesn't seem to work ...
> 
> for i in `ls -1 /some/dir` ; do
>         cat /some/dir/"$i" >> /usr/fruits.txt
> done
> 
> cat just gives me the odd error of files not being found, however, I can't
> see why the files wouldn't be found ... hrrm ...
> 
> thanks much for any info you might provide

(I've assumed that your '1' is a one, not an L. My font makes them both
look the same, but coping and pasting it elsewhere reveals that it is
indeed a 'one')

In my experience, you don't need -1 to get one column - ls does it
automatically in some circumstances (try ls | less if you don't
believe). This shouldn't be causing the problem though.

The problem is that your variable i will be getting the values like
'/some/dir/file', not 'file' as you have assumed. Verify this by using
an echo:

        for i in `ls -1 /some/dir` ; do
                echo "variable i = $i"
                cat /some/dir/"$i" >> /usr/fruits.txt
        done

... or by running with:

        $ sh -x <script>


Matthew

Reply via email to