Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
We just started on bash scripting in my college course, the problem is we're only dong 3 days on it. Our project for my class is to
"Write a bash script that takes an ordinary file as an argument and removes the file if its size is zero. Otherwise, the script displays file's name, size, number of hard links, owner and modify date (in this order) on one line. Your script must do appropriate error checking."
I've tried multiple ways of doing it by usin if then else statements, but I keep gettings errors, like integer expected, unexptected token.
Anybody know how a script like this would be written? Any help would be appreciated.

unexpected token etc comes often, when u dont have a whitespace between parenthesesif [this is true]; then..........<== WRONG
if [ this is true ]; then........<== RIGHTpost what youve tried and i will try to help you.

What would the actuall code look like? I tried starting from scratch and now I cant get it to work at all.
#!/bin/bash
if [ -f "$1" ]then
filename="$1"
set $(ls -il $filename)
filesize="$6"
hardlinks="$3"
owner="$4"
moddate="$7"
if [ "$filsize" == 0 ]
thenrm -r "$filename"
echo "$filename size was $filesize and was removed"exit 0
else
echo "File Hard Links Owner Modified Date"echo
echo "$filename $hardlinks $owner $moddate"
exit 1
fi
exit 2
fi

![]() |
![]() |
![]() |

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