linux 中输出变量字符串的长度

 

001、

[root@pc1 test]# a="abc"
[root@pc1 test]# b="abcde"
[root@pc1 test]# echo $a
abc
[root@pc1 test]# echo $b
abcde
[root@pc1 test]# echo ${#a}      ## 输出变量a的长度
3
[root@pc1 test]# echo ${#b}      ## 输出变量b的长度
5

 

 

002、

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt
d d g
d f g d
a d
[root@pc1 test]# cat a.txt | while read i; do echo ${#i}; done       ## 输出每行字符的长度
5
7
3

 

posted @ 2023-01-05 14:53  小鲨鱼2018  阅读(383)  评论(0编辑  收藏  举报