LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script to check the input string length (http://www.linuxquestions.org/questions/programming-9/bash-script-to-check-the-input-string-length-565312/)

fjkum 06-29-2007 04:59 AM

Bash script to check the input string length
 
Hi,

I would like to restrict user input to only 12 characters on the command line. How can I achive this using bash programming?

Many thanks.

fj

ghostdog74 06-29-2007 05:10 AM

Quote:

Originally Posted by fjkum
Hi,

I would like to restrict user input to only 12 characters on the command line. How can I achive this using bash programming?

Many thanks.

fj

Code:

# string="testing"
# echo ${#string}
7


bigearsbilly 06-29-2007 05:26 AM

summink like...

Code:

string=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
while [ ${#string} -ge 12 ];do
read string;
echo ${#string};done


cfaj 06-30-2007 09:43 PM

Quote:

Originally Posted by fjkum
I would like to restrict user input to only 12 characters on the command line. How can I achive this using bash programming?

Code:

read -n12 var


All times are GMT -5. The time now is 03:49 AM.