Jacob MeuserThu Dec 9 22:21:42 PST 2004
On Thu, Dec 09, 2004 at 07:41:47PM -0800, Allen Brown wrote: > On Thu, 9 Dec 2004, Jacob Meuser wrote: > > > On Thu, Dec 09, 2004 at 05:21:32PM -0800, Bob Miller wrote: > > > Jacob Meuser wrote: > > > > > > > ah, nice. I was worried about the leading spaces as well, but printf > > > > seems to take care of that: > > > > > > > > $ tb=0; for i in *; do b=`wc -c < $i`; b=`printf "%d" $b`; \ > > > > tb=`expr $tb + $b`; done; echo $tb > > > > > > You didn't quote $b before passing it to expr, so the shell will strip > > > off spaces there. > > > > > > $ tb=0; for i in *; do b=`wc -c < $i`; \ > > > tb=`expr $tb + $b`; done; echo $tb > > > > didn't work for me. shell is zsh 4.2.0 (i386-unknown-openbsd3.6). > > > > expr: non-numeric argument > > expr: syntax error > > expr: syntax error > > expr: syntax error > > ... > > > > -- > > <jakemsr at jakemsr.com> > > I'm not a zsh user. But if you put the following into a file > and make it executable it will work no matter what shell you > normally use. yes, this will be a script. I am aware that there are differences between the command line and a script, but I figured if it would work on the command line, that would be a good first step :) > #!/bin/bash > typeset -i tb=0 > for file in *; do tb=$tb+$(wc -c < $file); done > echo $tb well, that doesn't work with OpenBSD's /bin/sh. puff:~/ssm% echo $PATH /home/jakemsr/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin puff:~/ssm% cat /home/jakemsr/bin/file-size #!/bin/sh typeset -i bt=0 for file in * do tb=$tb+$(wc -c < $file) done echo $tb exit 0 puff:~/ssm% file-size + 1887 + 1360 + 3756 puff:~/ssm% ls -l total 16 -rw------- 1 jakemsr jakemsr 1887 Jun 17 20:45 43X.ssm -rw------- 1 jakemsr jakemsr 1360 Jun 17 20:46 a_synth.ssm -rw------- 1 jakemsr jakemsr 3756 Jun 17 20:46 carbohydrate.ssm puff:~/ssm% I'd rather rely on the existence of perl than bash ;/ > Well, actually, it has a defect. It doesn't behave correctly > when $i is a directory. Do you need this to work recursively > into subdirectories? no, not yet anyway. if needed, I could replace '*' with some `find` invocation and then step into subdirectories manually. -- <jakemsr at jakemsr.com>