LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   where is the diff: in these two program (https://www.linuxquestions.org/questions/linux-newbie-8/where-is-the-diff-in-these-two-program-660349/)

nakulashishsaxena 08-04-2008 09:08 AM

where is the diff: in these two program
 
here are the two codes

1> code 1
#!/bin/sh

echo -n "enter file name"
read file
c=0
sum=0
avg=0

cat $file |{
while read line; do
c=$(expr $c + 1)
sum=$(expr $sum + $c)
echo $$
#avg=`expr $sum / $c`
done
}

echo $$
echo $?
echo c= $d
echo sum= $sum
echo $avg= `expr $sum / $c`

2> code 2

#!/bin/sh

echo -n "enter file name"
read file
c=0
sum=0
avg=0

while read line; do
c=$(expr $c + 1)
sum=$(expr $sum + $c)
echo $$
#avg=`expr $sum / $c`
done < $file

echo $$
echo $?
echo c= $d
echo sum= $sum
echo $avg= `expr $sum / $c`
--------------------------------------------------------------------


I'm getting solution from second code,...
what i'm thinking is that processes is being forked as we called CAT command
but not fully satisfied
Can ny body help me?

Mr. C. 08-04-2008 06:01 PM

See: http://tldp.org/LDP/abs/html/redircb.html#REDIR2


All times are GMT -5. The time now is 04:35 AM.