我怎么能算的字符数量在bash变量 [英] how can I count the amount of characters in a bash variable

查看:71
本文介绍了我怎么能算的字符数量在bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能算在bash变量的所有字符?因此,举例来说,如果我有

how can I count all characters in a bash variable? so for instance if I had

"stackoverflow"

结果将是

"13"

我四处搜索在谷歌,但到目前为止只能够找出如何计算特定字符(说字母A为实例)

I've searched around on google, but so far have only been able to find out how to count specific characters (say the letter "a" for instance)

感谢您的帮助!

推荐答案

使用 $ {VAR#} 语法将计算变量的字符数。

Using the ${#VAR} syntax will calculate the number of characters in a variable.

<一个href=\"http://linux.about.com/od/bgb_guide/a/gdebgb78t01.htm\">http://linux.about.com/od/bgb_guide/a/gdebgb78t01.htm

这篇关于我怎么能算的字符数量在bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆