Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,403 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,192 people online right now. Registration is fast and FREE... Join Now!




script : value of count is becoming zero outside loop

 
Reply to this topicStart new topic

script : value of count is becoming zero outside loop

srishekh
7 Feb, 2008 - 04:27 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2006
Posts: 10


My Contributions
#! /bin/ksh
count=0
t1=0
find . -name "*.cpp" |
while read filename
do
tmp=`wc -l $filename |awk -F' ' '{ print $1 }'`
#echo $tmp
count=`expr ${count} + ${tmp}`
done
echo ${count}


User is offlineProfile CardPM
+Quote Post

TheMagnitude
RE: Script : Value Of Count Is Becoming Zero Outside Loop
7 Feb, 2008 - 02:43 PM
Post #2

D.I.C Head
Group Icon

Joined: 12 Jan, 2008
Posts: 88



Thanked: 1 times
Dream Kudos: 125
My Contributions
This isnt C++ or C, you got the wrong forum...
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Script : Value Of Count Is Becoming Zero Outside Loop
7 Feb, 2008 - 05:14 PM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,274



Thanked: 135 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Scope is a little odd in shell scripts.

One solution would be to dump the results into a temp file and grab them later. e.g.

CODE

#!/bin/ksh

tempFile=foo.txt
count=0
find . -name "*.cpp" |
while read filename; do
   tmp=`wc -l $filename  | sed "s/^\([0-9]*\).*/\1/"`
   count=`expr ${count} + ${tmp}`
   echo $count > $tempFile
done
cat $tempFile
rm -f $tempFile


Hope this helps.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:23AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month