Skip to main content
added 503 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

I think maybe you're relying a little too heavily on array types there - and variables in general. If I understand what you're doing up there correctly, I suspect this should do much of the same:

for a in checking google\ wallet savings cash
do  a=assets:$a
    printf "$a\t%d\n" "$(ledger -f finances balance "$a")"
done

That could probably be improved upon a great deal by somehow getting a reading of all values for $a above at once in a stream and then arranging it with a scripted editor like sed or similar. In general a shell variable is a pretty awful place to keep information of any value - or of any significant size for that matter. A shell variable should store only enough information to make retrieving actual information from a file more manageable.

Written as a shell function, the above might look like:

assets() if   [ "$#" -gt 0 ]
         then while [ "$#" -gt 0 ]
              do    printf "assets:%s\t%d\n" "$1" "$(
                    ledger -f finances balance "assets:$1")"
              shift;done
         else assets checking google\ wallet savings cash
         fi

...and could be called like:

assets

...for your default list, or like...

assets cash checking

...for a different list without every setting a single shell variable value at all.

I think maybe you're relying a little too heavily on array types there - and variables in general. If I understand what you're doing up there correctly, I suspect this should do much of the same:

for a in checking google\ wallet savings cash
do  a=assets:$a
    printf "$a\t%d\n" "$(ledger -f finances balance "$a")"
done

That could probably be improved upon a great deal by somehow getting a reading of all values for $a above at once in a stream and then arranging it with a scripted editor like sed or similar. In general a shell variable is a pretty awful place to keep information of any value - or of any significant size for that matter. A shell variable should store only enough information to make retrieving actual information from a file more manageable.

I think maybe you're relying a little too heavily on array types there - and variables in general. If I understand what you're doing up there correctly, I suspect this should do much of the same:

for a in checking google\ wallet savings cash
do  a=assets:$a
    printf "$a\t%d\n" "$(ledger -f finances balance "$a")"
done

That could probably be improved upon a great deal by somehow getting a reading of all values for $a above at once in a stream and then arranging it with a scripted editor like sed or similar. In general a shell variable is a pretty awful place to keep information of any value - or of any significant size for that matter. A shell variable should store only enough information to make retrieving actual information from a file more manageable.

Written as a shell function, the above might look like:

assets() if   [ "$#" -gt 0 ]
         then while [ "$#" -gt 0 ]
              do    printf "assets:%s\t%d\n" "$1" "$(
                    ledger -f finances balance "assets:$1")"
              shift;done
         else assets checking google\ wallet savings cash
         fi

...and could be called like:

assets

...for your default list, or like...

assets cash checking

...for a different list without every setting a single shell variable value at all.

Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

I think maybe you're relying a little too heavily on array types there - and variables in general. If I understand what you're doing up there correctly, I suspect this should do much of the same:

for a in checking google\ wallet savings cash
do  a=assets:$a
    printf "$a\t%d\n" "$(ledger -f finances balance "$a")"
done

That could probably be improved upon a great deal by somehow getting a reading of all values for $a above at once in a stream and then arranging it with a scripted editor like sed or similar. In general a shell variable is a pretty awful place to keep information of any value - or of any significant size for that matter. A shell variable should store only enough information to make retrieving actual information from a file more manageable.