Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash arithmetics

# Basic arithmetic using let
let a=5+4
echo $a # 9
let "a = 4 * 5"
echo $a # 20
let a=4*5 # No spaces, Skip the asterisk '*'
echo $a # 20
let a++
echo $a # 21

# Basic arithmetic using expr
a=$( expr 10 - 3 )
echo $a # 7
expr 5 + 4 #9
expr "5 + 4" #5 + 4, Strings are not evaluated
expr 5+4 #5+4, Spaces are required
expr 5 * 2 #10
expr ( 11 % 2 ) + 5 #6, parenthesis must be escaped

# Basic arithmetic using double parentheses
a=$(( 3 * 3 ))
echo $a # 9
b=$(( a + 4 ))
echo $b # 12
b=$(( $a + 4 ))
echo $b # 12
(( b++ ))
echo $b # 13
(( b += 3 ))
echo $b # 16

# Show the length of a variable.
a='Hello World'
echo ${#a} # 11
b=4953
echo ${#b} # 4
Comment

PREVIOUS NEXT
Code Example
Shell :: connect compute instance aws to vs code 
Shell :: how to install amethyst on mac 
Shell :: which email is github using locally 
Shell :: Find all pods that status is NotReady sort count jq cheatsheet 
Shell :: How to change first occurrence of word in a string 
Shell :: Bash script to authenticate machine users 
Shell :: Fix for infinite log Linux bug 
Shell :: cargo generate 
Shell :: Error from chokidar Error: ENOSPC: System limit for number of file watchers reached, 
Shell :: apt upgrade vs full-upgrade 
Shell :: ubuntu install jitsi 
Shell :: gatsby install 
Shell :: git stash only untracked files 
Shell :: How to get Tab-Completions with microsoft vcpkg 
Shell :: delete .lastupdated maven 
Shell :: ansible remove part of line 
Shell :: Target Packages (main) 
Shell :: git: Download specific commit from git repository : remote 
Shell :: linux scheduled shutdown 
Shell :: how to read an input in bash 
Shell :: enable synatax hightlighting in nano 
Shell :: what is the difference between npm uninstall and remove 
Shell :: bit bucket 
Shell :: 7zip split archive command line fat32 
Shell :: Binding to singularity additional volume 
Shell :: how to create a soft link in bash 
Shell :: git branch description 
Shell :: docker unpause 
Shell :: powershell get-aduser global catalog 
Shell :: jq select where value starts with 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =