shanenin Posted July 23, 2005 Report Share Posted July 23, 2005 (edited) I am trying to use bash to test for the length of a string. Nothing seems to be making sence to me. this code tests(and works) for a string larger then 7#!/bin/bashPASS=asdfghjklif [[ `echo ${#PASS}` > 7 ]] then echo "works"fibut it fails with an error if I use '>=' like this. Why?#!/bin/bashPASS=asdfghjklif [[ `echo ${#PASS}` >= 7 ]] then echo "works"fiI would think the following code would test for a string larger then 7 but smaller then 11, but this is not testing as true, it is testing as false #!/bin/bashPASS=asdfghjklif [[ `echo ${#PASS}` > 7 ]] && [[ `echo ${#PASS}` < 11 ]] then echo "works"fithanks for helping me sort this outedit added later//the problem seems to be specifically with this test. It is returning a 1, why is it not returning a 0 ?#!/bin/bashPASS=asdfghjkl[[ `echo ${#PASS}` < 11 ]]echo $? Edited July 23, 2005 by shanenin Quote Link to post Share on other sites
shanenin Posted July 23, 2005 Author Report Share Posted July 23, 2005 (edited) doing it like this works#!/bin/bashPASS=asdfghjklif (( ${#PASS} > 7 )) && (( ${#PASS} < 11 )) then echo "works"fi Edited July 23, 2005 by shanenin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.