轉載自 http://stackoverflow.com/questions/17368067/length-of-string-in-bash $ myvar="some string" $ echo ${#myvar} 11 Just do this: size=${#myvar} To confirm it was properly saved: $ echo $size 11