简体   繁体   中英

How to define two variable x=20, y=5 and then to print division of x and y (i.e. x/y) - bash

I am using Ubuntu 14.04 and i tried this :

$ x=20  
$ y=5  
$ expr x / y 

But i got this error:

expr: non-integer argument

您必须展开变量以获取其值: $x$y

expr $x / $y

Using modern Bash arithmetics:

echo $((x / y))

To assign the result to a variable z :

((z = x / y))

To verify the value of z :

echo $z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM