我如何计算一个bash变量中的字符数量 [英] how can I count the amount of characters in a bash variable

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

问题描述

如何计算bash变量中的所有字符?所以例如,如果我有

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

"stackoverflow"

结果将是

"13"

我已经在google上搜索过,但到目前为止,只能找出如何计算特定字符(比如说一个例如)

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.

http:// linux.about.com/od/bgb_guide/a/gdebgb78t01.htm

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

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