Shell script problem

Patton Echols p.echols at comcast.net
Tue Mar 2 09:59:39 UTC 2010


On 03/02/2010 12:49 AM, Vijay Shanker Dubey wrote:
>
>     By the way, Vijay.  To get your scrip to actually join files, you
>     do not
>     need the last fiddly loop.  Take it out and put in this:
>
>
> :(
>  
>
>     joinCommand="mencoder -oac copy -ovc copy -o"
>
>     #add output file name
>     joinCommand="$joinCommand $OUTPUT_FILE_NAME"
>
>     # append files
>     joinCommand="$joinCommand ${FILES[@]}"
>
>  
> WOW great to see this. I was not aware of this.   Thanks man.. I was 
> not able to use that script as that loop was not working in my case. 
> It was only adding first file in the final command.
>


No problem.  Since the shell will expand the array, no loop required.  
But to make the "for loop" work it needed to be like this:
=========
echo "Going to execute command $joinCommand"
for file in ${FILES[@]} ; do 
    echo "Going to execute command $joinCommand"
    joinCommand="$joinCommand $file"
done   

=============
Notice that what you have basically done is expand the FILES array into 
the file variable!  To make your script more efficient, you may want to 
take out the "yes" requirement and just test each file name for "done" 
or something like that.




More information about the ubuntu-users mailing list