Computing.Net > Forums > Unix > Unsolvable problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unsolvable problem

Reply to Message Icon

Name: Milen
Date: October 21, 2002 at 10:49:08 Pacific
OS: Linux Red Hat 5.2
CPU/Ram: does not matter
Comment:

Can you please tell me where the mistake in the following script is? It seems to be doing what it is supposed to do but the problem is that there is a mistake which sould be found


$ test.sh /etc/passwd /var/log/messages

Content of test.sh:
totalsize=0
for afilename in $*
do
size=`du -k $afilename|sed -e 's/^\([0-9]*\).*$/\1/'`
((totalsize=totalsize+size))
done
echo "Total Size = ${totalsize}k"



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: October 21, 2002 at 11:16:55 Pacific
Reply:

What is the mistake that you see?

On my machine (Redhat Linux 7.?), du -k displays the size and filename, ie.

> du -k file1
20 file1

I would expect that having the filename in the variable 'size' would mess up the addition statement


0

Response Number 2
Name: Ned
Date: October 23, 2002 at 11:55:41 Pacific
Reply:

Your script will only work with Korn shell not with anyother shell. It appears that your default shell is not a Korn shell.

The first line of your script should be:
#!/bin/ksh


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Auto say y or n in a shel... Set xterm's



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unsolvable problem

Help: problems installing 9 gig hd in SCO UNIX 3.2v4 www.computing.net/answers/unix/help-problems-installing-9-gig-hd-in-sco-unix-32v4/1648.html

FTP File Size Problem from UNIX to www.computing.net/answers/unix/ftp-file-size-problem-from-unix-to/4240.html

IP Address problem www.computing.net/answers/unix/ip-address-problem/1386.html