length of the string in linux shell

Life is short , play more!
本文来自lihao's Blog,转载请注明。

[[email protected] ~]# TEST_CHAR=kkkkkkk
[[email protected] ~]# echo $TEST_CHAR | wc -c (\n is printed by the echo)
8
[[email protected] ~]# echo ${#TEST_CHAR}
7
[[email protected] ~]#
[[email protected] ~]# echo $TEST_CHAR | awk '{print length $0}'
7kkkkkkk
[[email protected] ~]# echo $TEST_CHAR | awk '{print length ($0)}'
7
[[email protected] ~]# expr length $TEMP_CHAR
expr: syntax error
[[email protected] ~]# echo `expr length $TEMP_CHAR`
expr: syntax error
[[email protected] ~]# echo `expr length '$TEMP_CHAR'`
10
[[email protected] ~]# expr length '$TEMP_CHAR'
10


发表评论

电子邮件地址不会被公开。 必填项已用*标注