Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4328662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:42:56+00:00 2026-05-21T09:42:56+00:00

Consider: t=0 ; for i in 1 2 3 4 5 6 7 8

  • 0

Consider:

t=0 ; for i in 1 2 3 4 5 6 7 8 9 10 ; do t=$((t+i)) ; done ; echo $t

prints 55.

But:

totsize=0
find /home/user -type f -mmin -4860 -a -mmin +3420 | xargs du | \
while read size rest ; do
    totsize=$((totsize+size))
    echo "$totsize"
done
echo "Sum: $totsize kb"

Prints “Sum: 0 kb” even tho the interim print statement prints a reasonable sum.

I know I have encountered this issue before, but have never understood it. What is difference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:42:57+00:00Added an answer on May 21, 2026 at 9:42 am

    that’s because the pipes create a subshell so totsize is “local” inside that subshell. you can try this instead (bash)

    totsize=0
    while read size rest ; do
        totsize=$((totsize+size))
        echo "$totsize"
    done < <(find /home/user -type f -mmin -4860 -a -mmin +3420 | xargs du)
    echo "Sum: $totsize kb"
    

    Or instead of using bash, call awk

    $> find /home/user -type f -mmin -4860 -a -mmin +3420 | xargs du | awk  '{s+=$1}END{print "total size: "s}'
    

    But are you sure you want to use just du without any options, because the size is not “accurate” (using du -b would be better). If you have GNU find, you can use -printf

    find /home/user -type f -mmin -4860 -a -mmin +3420 -printf "%s\n" | awk  '{s+=$1}END{print "total size: "s" bytes"}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following situation: Development is mainly done in trunk. Branches are used when
Consider the following query: SELECT domain, done FROM tasks WHERE 1 GROUP BY domain
I am curious as to why data validation is done using buddy classes. Consider
Consider the following code snippet that takes user input (a date) and format it
Consider a typical relational structure: Answer has many comments. comments belongs to a user,
I've done a lot of Googling, but haven't found anything, so I'm really sorry
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider this problem: I have a program which should fetch (let's say) 100 records

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.