First off, I don’t see what this has to do with Red Hat…
As for your problem, the most elegant solution involves bash arrays like so:
Code:
while read fullline; do
line=(${fullline})
y=${#line[*]}
for i in $(seq 0 $(($y - 1))); do
echo -n "${line[$i]} "
done; echo
# echo ${line[*]}
# cp ${line[*]}
done < arg.txt
This code sample reads in one line at a time to the variable “fullline”. In each iteration of the outer loop, an array called “line” is declared with contents of $fullline, but each in a separate index of the array. So you could access each element of the array by index, starting at 0 (for example, in the first iteration of the loop, if you said “echo ${line[2]}”, it would output “oi3”). You can access all the elements of the array with spaces in between with “${line[*]}”, and you can access the number of elements with “${#line[*]}”. The for loop simply prints each element followed by a space, and a final newline (the same thing could more easily have been accomplished by uncommenting the line in blue). If you change, for example, the number in red from “1” to “2”, you print out all but the last element (i.e., arg1 arg2 arg3 … arg(y-1)). Finally, the line in green (if uncommented) does what you ask — “cp arg1 arg2 arg3 … arg(y-1) argy”.
I suggest you
read up on bash arrays. If you have any questions, just post.