문제

Let's say I want to check if the first argument is 2 characters long. I tried

if [ ${#$1} -e 2]

but it doesn't work.

도움이 되었습니까?

해결책

  • Don't use $ in the parameter expansion
  • Use -eq for numerical comparison
  • Add a space before the ]:

All in all:

if [ ${#1} -eq 2 ]
then
  echo "It's two characters long"
fi
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top