LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2007, 03:59 AM   #1
fjkum
Member
 
Registered: Feb 2006
Posts: 40

Rep: Reputation: 15
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
 
Old 06-29-2007, 04:10 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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
 
Old 06-29-2007, 04:26 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
summink like...

Code:
string=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
while [ ${#string} -ge 12 ];do 
read string;
echo ${#string};done
 
Old 06-30-2007, 08:43 PM   #4
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
How can I check if there slash in the end of string in bash if? nadavvin Programming 5 01-27-2007 02:41 AM
looking for string on particular line - bash script tara Linux - General 9 12-14-2005 05:43 PM
Bash Script String Splitting MurrayL Linux - Newbie 1 09-21-2004 03:20 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration