Linux expr命令

Linux 教程 · 2019-02-14 16:58:16

expr命令是一个手工命令行计数器,用于在UNIX/LINUX下求表达式变量的值,一般用于整数值,也可用于字符串。

语法

expr 表达式

表达式说明:

  • 用空格隔开每个项;
  • 用 / (反斜杠) 放在 shell 特定的字符前面;
  • 对包含空格和其他特殊字符的字符串要用引号括起来

实例

1、计算字串长度

> expr length “this is a test”
 14

2、抓取字串

> expr substr “this is a test” 3 5
is is

3、抓取第一个字符数字串出现的位置

> expr index "sarasara"  a
 2

4、整数运算

 > expr 14 % 9
 5
 > expr 10 + 10
 20
 > expr 1000 + 900
 1900
 > expr 30 / 3 / 2
 5
 > expr 30 \* 3 (使用乘号时,必须用反斜线屏蔽其特定含义。因为shell可能会误解显示星号的意义)
 90
 > expr 30 * 3
 expr: Syntax error

点击查看所有 Linux 教程 文章: https://www.codercto.com/courses/l/14.html

查看所有标签

Effective JavaScript

Effective JavaScript

David Herman / Addison-Wesley Professional / 2012-12-6 / USD 39.99

"It's uncommon to have a programming language wonk who can speak in such comfortable and friendly language as David does. His walk through the syntax and semantics of JavaScript is both charming and h......一起来看看 《Effective JavaScript》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码