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 -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -