I am writing a script below, which has 2 loops. The outer one reads file sufffixed with a number and inner inside which loop through each line of the file and display each space delimited string. However, i find that the string printed out in the inner loop includes not only the delimited string in the file, but also the filename in the same directories.
#!/bin/bash
process_file="/home/eclipse/misc/crontab.all"
rm $process_file
for ((i =5;i<=5;i++))
do
host="edev$i"
filename="/home/eclipse/misc/$host.crontab"
ssh eclipse@$host crontab -l|grep start|grep -v \# > $filename
echo $filename
echo "Processes on $host:" >> crontab.all
while read line;
do
echo "line=$line"
STR_ARRAY=(`echo $line | tr "," "\n"`)
for y in "${STR_ARRAY[@]}"
do
echo "> [$y]"
done
done < $filename
done
The result is the same if i replaced the inner loop by:
for word in $line
do
echo $word
done
Anyone can help? Thanks.