Sample Header Ad - 728x90

Verify the length of a variable

44 votes
3 answers
157514 views
I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this: #!/bin/bash read string check=${#string} echo $check if [ $check -ge 5 ]; then echo "error" ; exit else echo "done" fi is there a more "elegant" solution?
Asked by Pol Hallen (2257 rep)
Jul 17, 2014, 05:08 PM
Last activity: Mar 8, 2025, 09:03 AM