Unix Beginner needs help

how do i implement a script that asks user to input a word. it should ask for input a word continuously until the word is longer than 5 characters then stop.
this is what i have so far

#!/bin/bash
read -p "enter word" word1
while [ "word1"; -lt 5 ]; do
 echo "continue"
done

There is no post test loop construct in bash so you have to do something like the following:

read -p"Go on say it: " word1
while [ $(echo $word1 | wc -c ) -lt 5 ]; do
  read -p"Go on say it: " word1  
done
echo $(expr length $word)

or with ksh/bash:

echo ${#word}

gives the length of the variable.

2 Likes

I'll post a version which unify the comments :

#!/bin/bash
word1=""
while [ ${#word1} -lt 5 ]
do
  read -p "enter word" word1
done

I don't like writing the read line multiple times, it leads to unwanted behavior :rolleyes:

Thanks a lot