Celeb Glow
updates | March 19, 2026

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

I tried this but i am getting error:

ubuntu@ubuntu-VirtualBox:~/Documents$ x=20
ubuntu@ubuntu-VirtualBox:~/Documents$ y=5
ubuntu@ubuntu-VirtualBox:~/Documents$ expr x / y
expr: non-integer argument
1

1 Answer

You need to add $ in front of a variable name to refer to its contents.

pilot6@Pilot6:~$ x=20
pilot6@Pilot6:~$ y=5
pilot6@Pilot6:~$ expr $x / $y
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy