Visit The New, Modern Unix Linux Community


Execution Problems with the value is not store in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problems with the value is not store in a variable
# 1  
Execution Problems with the value is not store in a variable

Code:
#!/bin/bash
filecount=0
dirname=path.log
exec<$dirname
while read line # line by line read source file name and stored in a veribale
do
        sourcedirname=$line
        (   
        count=`ls $sourcedirname |wc -l`
        filecount=`expr $filecount + $count` 
        echo $filecount
        )   
done

This is the script . The output of this script is :
Code:
6
2

But actual should be :
Code:
6
8

Two directory path are mention in path.log file.
Code:
/home/test1
/home/test2

6 file present in test1 directory and 2 file present in test2 directory. I want to add the total file of those directory. Directory may be increase, here only two directory.

Moderator's Comments:
Mod Comment Having so many posts already, you should be familiar using code tags - you got a PM.

Last edited by zaxxon; 11-19-2010 at 09:41 AM..
# 2  
You are invoking a subshell each time in the loop and hence the variable $filecount is reset each time. don't use braces.
# 3  
Quote:
Originally Posted by anchal_khare
You are invoking a subshell each time in the loop and hence the variable $filecount is reset each time. don't use braces.
Thanks a lot

Its work fine

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #763
Difficulty: Medium
L4 caches are currently very common in computer systems.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. UNIX for Dummies Questions & Answers

Execution Problems with UNIX.

Hi Team, I created one file like tst.pl, it contains #!/usr/bin/perl use Spreadsheet::ParseExcel; During execution it's showing error like use: command not found. Pleast let me suggest how to use this perl menthods in Unix. Thanks in Advance, Reards, Harris (5 Replies)
Discussion started by: harris
5 Replies

3. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

4. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Hi friends, today i created a cron job , registered the crontab file associated but dont know why the cron is not getting executed at the right time.?? content of Crontab file : 21 15 * * * /subrat/myt i wanted to execute the script myt on 15:21 PM of everyday. the script myt... (2 Replies)
Discussion started by: paras.oriental
2 Replies

5. Shell Programming and Scripting

Execution Problems with Cron

Hi, I have written a shell script to transfer files to a SFTP server passing the filername, source and dest directory as parameters and it runs well. :) I want to schedule this script to run periodically using a cron job. root@pingu # cat /etc/crontab SHELL=/bin/bash... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

6. Homework & Coursework Questions

Execution Problems with sed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Okay so I am taking bash scripting this semester and we are now working on the stream editor sed. For our book we... (4 Replies)
Discussion started by: aggie6970
4 Replies

7. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

8. UNIX and Linux Applications

Execution Problems with Cron

Hi all!! I have a nerve-wracking concept (probably for me!!) which is not understood. My crontab entry looks this way. 33 09 22 3 * /home/myexp.sh "Bgp4 ALL" >/dev/null 2>&1 But cron gets started occasionally. Sometimes it does. Sometimes it does not. And sometimes it hangs in the middle (I... (1 Reply)
Discussion started by: dhivyasuresh
1 Replies

9. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

10. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

Featured Tech Videos