0

I have the following bash script:

#!/bin/bash
if [ ! -f numbers ]; then echo 0 > numbers; fi
count = 0
while [[$count != 100]]; do
count = `expr $count + 1`
done

When I run it in terminal on my Mac, I get the following output:

seq_file_gen.sh: line 3: count: command not found
seq_file_gen.sh: line 4: [[: command not found

Why am I getting these errors? This script was given to me by my teacher so I have no idea why I can't get this script to run. Any help would be greatly appreciated.

EDIT: This is the correct way to write this script (with spaces)

 #!/bin/bash
 if [ ! -f numbers ]; then echo 0 > numbers; fi
 count=0
 while [[ $count != 100 ]]; do
 count=`expr $count + 1`
 done
6
  • What is the reason for the down vote? It seems impossible to ask a basic question without getting down voted. Commented Feb 9, 2015 at 20:18
  • 1
    Do not use spaces around the equals: write count=0 and count=`expr $count + 1`. I didn't apply the downvote, but I suppose it may be because these are basic shell syntax issues that are determined from reading documentation. Commented Feb 9, 2015 at 20:24
  • 1
    also you still don't have space in 100]] and what's with the 'numbers' on line 2? Is this even a complete script? Commented Feb 9, 2015 at 20:25
  • I forgot to change it. It worked after I put the space back in. Thanks for the help. Will accept as best answer when I am able to. Commented Feb 9, 2015 at 20:26
  • 1
    You can always run your programs with shellcheck.net to get some fast checking with good explanations. Commented Feb 9, 2015 at 20:45

1 Answer 1

1

Add spaces before/after [[ and ]] like so:

while [[ $count != 100 ]]; do
Sign up to request clarification or add additional context in comments.

Comments

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.