Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use double bracket for arithmetic operation in bash #2

Open
mhdzumair opened this issue Jun 7, 2021 · 0 comments
Open

Use double bracket for arithmetic operation in bash #2

mhdzumair opened this issue Jun 7, 2021 · 0 comments

Comments

@mhdzumair
Copy link

Description:
Sir we can use double bracket for arithmetic operation in bash is more flexible way because it doesn't matter if there is a bracket or not. So I'm kindly suggesting to replace / include this double bracket guide.

Suggested Labels:
Improvement

Suggested Assignees:
Affected Product Version:
OS, DB, other environment details and versions:
Steps to reproduce:
Related Issues:

Current Code:

#!/bin/sh

A=70
B=90

val=`expr $A + $B` #Be Mindful about the spaces in between the "expr" , $A , + , $B  characters, 
#                  which  is a must. Otherwise script will throw a syntax error 
echo "A + B : $val"

val=`expr $A - $B`
echo "A - B : $val"

val=`expr $A \* $B`
echo "a * b : $val"

val=`expr $B / $A`
echo "B / A : $val"

val=`expr $B % $A`
echo "B % A : $val

Suggesting Code

#!/usr/bin/bash

A=70
B=90

((val = $A + $B))
echo "A + B : $val"

((val=$A-$B))
echo "A - B : $val"

((val= $A * $B))
echo "a * b : $val"

((val = $B / $A))
echo "B / A : $val"

((val= $B % $A))
echo "B % A : $val"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant