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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -