【Linux】一步一步学Linux——expr命令(265)
生活随笔
收集整理的這篇文章主要介紹了
【Linux】一步一步学Linux——expr命令(265)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
00. 目錄
文章目錄
- 00. 目錄
- 01. 命令概述
- 02. 命令格式
- 03. 常用選項
- 04. 參考示例
- 05. 附錄
01. 命令概述
expr命令將表達式的值列印到標準輸出。
expr命令的英文全稱是“expression”,是一款表達式計算工具,使用它完成表達式的求值操作。
02. 命令格式
用法:expr 表達式或:expr 選項03. 常用選項
--help 顯示此幫助信息并退出--version 顯示版本信息并退出常用的表達式
可用的表達式有:ARG1 | ARG2 若ARG1 的值不為0 或者為空,則返回ARG1,否則返回ARG2ARG1 & ARG2 若兩邊的值都不為0 或為空,則返回ARG1,否則返回 0ARG1 < ARG2 ARG1 小于ARG2ARG1 <= ARG2 ARG1 小于或等于ARG2ARG1 = ARG2 ARG1 等于ARG2ARG1 != ARG2 ARG1 不等于ARG2ARG1 >= ARG2 ARG1 大于或等于ARG2ARG1 > ARG2 ARG1 大于ARG2ARG1 + ARG2 計算 ARG1 與ARG2 相加之和ARG1 - ARG2 計算 ARG1 與ARG2 相減之差ARG1 * ARG2 計算 ARG1 與ARG2 相乘之積ARG1 / ARG2 計算 ARG1 與ARG2 相除之商ARG1 % ARG2 計算 ARG1 與ARG2 相除之余數字符串 : 表達式 定位字符串中匹配表達式的模式match 字符串 表達式 等于"字符串 :表達式"substr 字符串 偏移量 長度 替換字符串的子串,偏移的數值從 1 起計index 字符串 字符 在字符串中發現字符的地方建立下標,或者標0length 字符串 字符串的長度+ TOKEN interpret TOKEN as a string, even if it is akeyword like 'match' or an operator like '/'( EXPRESSION ) value of EXPRESSION04. 參考示例
4.1 加法運算
[deng@localhost tmp]$ expr 2 + 3 5 [deng@localhost tmp]$4.2 減法運算
[deng@localhost tmp]$ expr 10 - 8 2 [deng@localhost tmp]$4.3 乘法運算
[deng@localhost tmp]$ expr 3 \* 5 15 [deng@localhost tmp]$4.4 除法運算
[deng@localhost tmp]$ expr 15 / 3 5 [deng@localhost tmp]$4.5 求余運算
[deng@localhost tmp]$ expr 10 % 3 1 [deng@localhost tmp]$4.6 連除運算
[deng@localhost tmp]$ expr 100 / 2 / 2 25 [deng@localhost tmp]$4.7 計算字符串長度
[deng@localhost tmp]$ expr length "hello world" 11 [deng@localhost tmp]$4.8 獲取子串
[deng@localhost tmp]$ expr substr "hello world" 3 4 llo [deng@localhost tmp]$4.9 獲取字符串中第一次出現指定字符的位置
[deng@localhost tmp]$ expr index "hello world" l 3 [deng@localhost tmp]$4.10 邏輯運算
[deng@localhost tmp]$ expr 3 \< 5 1 [deng@localhost tmp]$4.11 獲取隨機數
[deng@localhost tmp]$ expr $RANDOM % 100 + 1 30 [deng@localhost tmp]$05. 附錄
參考:【Linux】一步一步學Linux系列教程匯總
總結
以上是生活随笔為你收集整理的【Linux】一步一步学Linux——expr命令(265)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux】一步一步学Linux——p
- 下一篇: linux 其他常用命令