I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this:#!/bin/bashread stringcheck=${#string}echo $checkif [ $check -ge 5 ]; then echo error ; exitelse echo donefiis there a more elegant solution?
Verify the length of a variable
bash;shell;string
More elegant? NoShorter? Yes :)#!/bin/bashread stringif [ ${#string} -ge 5 ]; then echo error ; exitelse echo donefiAnd if you have no problem on trading more elegance in favor of being shorter, you can have a script with 2 lines less:#!/bin/bashread string[ ${#string} -ge 5 ] && echo error || echo doneYou could use double brackets if you think it is safer. Explanation here.