if statement - How can I check the length of an argument in bash? -
let's want check if first argument 2 characters long. tried
if [ ${#$1} -e 2]
but doesn't work.
- don't use $ in parameter expansion
- use
-eq
numerical comparison - add space before
]
:
all in all:
if [ ${#1} -eq 2 ] echo "it's 2 characters long" fi
Comments
Post a Comment