shanenin Posted July 23, 2005 Report Share Posted July 23, 2005 (edited) I have been messing around with a bash script to test if characters are in a string#!/bin/bashread PASSX=${#PASS}Y=0while (( Y < X )); do if [[ ${PASS:$Y:1} != [a-zA-Z1-9] ]]; then break fi let Y+=1done(( Y == X ))notice this line in particularwhile (( Y < X )); doI called my variables without using the $ like this $Y and $X, and it still works. WHY?it also works like thiswhile (( $Y < $X )); do Edited July 23, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted July 24, 2005 Report Share Posted July 24, 2005 It works because it works. The Bourne shell is the wrong to place to look if you're trying to find consistency.The POSIX definition of arithmetic substitution includes only the $(()) form. I think it also requires dollar prefixes for variables, but I'm not sure. The alterate syntaxes (both the bare (()) and the 'let' form) were introduced in ksh and adopted by bash. Quote Link to post Share on other sites
shanenin Posted July 24, 2005 Author Report Share Posted July 24, 2005 thanks for the explanation.it turns out my script was pretty meaningless. I could have just done[[ ${VAR} == *[^a-bA-B1-9]* ]]or [[ ${VAR} == *[^[:alnum:]]* ]] 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.