![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Error with the following script
Greetings again. I made a program that tells the size of a dictionary and stores it into a temp.txt file. Code:
temp="temp.txt"
if [ $# -ne 1 ]; then
echo "Wrong parameter"
else
if [ -d "$1" ]; then
rm "$temp" #Delete any previous temp file
find "./$1" -maxdepth 1 -type f >> "$temp"
#save the found files to the temp file
IFS=" #set for breaking characters
"
size=0
files=`cat "$temp"` #read the temp file
rm "$temp"
#delete the temp file (making sure its size wont be read)
#size counting
for i in $files; do
if [ -f $i ]; then
size=$(expr $size + $(stat -c%s "$i"))
fi
done
echo "The directory's size is : $size"
else
echo "A non directory parameter was given"
fi
fi
the problem is the script doesn't create the temp.txt file. if i create one then it deletes it so the deleting part is okay. the script - as it is at the moment - also tells the correct size of the dictionary, so that part seems to be okay aswell. i just cannot fix it:/ Thanks in advance! |
|
||||
|
My impression is that you are posting homework in the main forums.
To post homework, you must follow homework posting rules in the proper forum. Also, you need to write more descriptive subjects. Here is a link to the rules. Please read them and follow them. Thanks! The UNIX and Linux Forums - Forum Rules |
|
|||
|
The script deletes temp.txt after creating and reading back reading the file. Quote:
Quote:
Consider replacing ">>" with ">" in the "find" line such that it creates the file if it does not exist or overwrites the file if it does exist. Code:
find "./$1" -maxdepth 1 -type f > "$temp" Last edited by methyl; 12-01-2009 at 11:36 AM.. Reason: typo |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting error while calling a script within a script | sriniu190 | Shell Programming and Scripting | 6 | 10-07-2009 07:39 AM |
| Script with error output but continuation in script? | daem0n | Shell Programming and Scripting | 3 | 08-23-2009 11:10 PM |
| FTP script error | Lenora2009 | Shell Programming and Scripting | 21 | 07-23-2009 06:15 PM |
| script error | xipiska | Shell Programming and Scripting | 4 | 06-26-2008 02:36 PM |
| awk Shell Script error : "Syntax Error : `Split' unexpected | Herry | UNIX for Dummies Questions & Answers | 2 | 03-17-2008 11:16 AM |