| | |
length of a variable!
![]() |
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
Hey There,
In bash (and similar shells) you can use read with the -n flag, like:
read -n4
if you want to limit the variable input to 4 characters.
If you want to just trim your variables, you can check the length of a variable by gettings the length value and running a simple if compare. so, if:
var=12345
echo $var = 12345
echo ${#var} = 5
if [ ${#var} -gt 4 ]
then
bail
fi
Hope that helps
, Mike
In bash (and similar shells) you can use read with the -n flag, like:
read -n4
if you want to limit the variable input to 4 characters.
If you want to just trim your variables, you can check the length of a variable by gettings the length value and running a simple if compare. so, if:
var=12345
echo $var = 12345
echo ${#var} = 5
if [ ${#var} -gt 4 ]
then
bail
fi
Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Similar Threads
- Using "variable variables" in Javascript (JavaScript / DHTML / AJAX)
- [Warning] address of local variable returned??? (C++)
- Java help (Java)
- how to find length of a string (C++)
- Time of a java method (Computer Science)
- Drop 0 in floating point variable 0.233 (C++)
- Need Help counting Array Length (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: Input file!
- Next Thread: DOS 6.22
| Thread Tools | Search this Thread |





