1

I'm getting an error with my script for the last line of the file and I'm not sure why:

./sampledata: line 55: syntax error: unexpected end of file

Example Code:

#!/bin/bash

temptime=$(date +"%H:%M")

usercount=0
while word in userfile
{ usercount=$usercount+1 }


counter=0
usercount=$usercount/2 #format

echo -n $temptime " |" >> numusersfile

while $counter -le $usercount
{
    echo -n "*" >> numusersfile
    counter=$counter+1
}
echo "" >> numusersfile

Am I doing my loops correctly? Or is there something wrong with how I'm writing to the file? I'm kinda stumped on this right now..

1 Answer 1

1

while loops in bash should be like this:

while [ $counter -le $usercount ]
do
    echo -n "*" >> numusersfile
    counter=$counter+1
done

Mind the spaces around [ and ] and that brackets are replaced with do and done

Sign up to request clarification or add additional context in comments.

2 Comments

If one follows McConnell's practice, bring the do up after the test, like: while [ $counter -le $usercount ]; do
This fixes the EOF error but I'm now left with other errors, I'll update the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.