1

a simple shell script:

#!/bin/sh
str="hello"
while [ -n $str ]; do
  #do noting, just loop infinitely
done

this script throws an error, like this:

./while.sh: 5: ./while.sh: Syntax error: "done" unexpected

why, and what is the correct way ?

1 Answer 1

2

You need to do something! The shortest thing you can do is this:

#!/bin/sh
str="hello"
while [ -n "$str" ]; do
  :
done

:, a shorthand for true, does nothing and returns success.

By the way, I quoted your string $str, as this is something that you should always 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.