Thursday, May 19, 2022

Bash scripting 5

Basic Arithmetic Operations 



Arithmetic Operations:
  • Arithmetic operations are some of the basic mathematical operations like addition,subraction,...
  • These small steps can be developed into a big code with massive logic.
  • Basic mathematics knowlegde is enough to play with it.
  • There are several steps to perform mathematical operations in bash:
    • The expression should begin with "$"
    • After "$" , two open and close paranthesis ,$((  ))
    • It should have one space after opening paranthesis and one space before paranthesis.
    • The expression value can be stored in a variable and also it can be directly printed as the output.
    • Example : $(( val_1 + val_2 ))    It can be any valid operator.
    • Lets run a operation directly in terminal.



    • The between the values and operator is optional.
    • Lets create a bash program ,That get two values and perform certain operations



  • We can use build-in variables to perform mathematical operations.
  • For Example,
    • We can use $RANDOM and generate a random single digit number










No comments:

Post a Comment

Google Cybersecurity Professional Certificate

    Google Cybersecurity Professional Certification 🔒 Google Cybersecurity Professional Certification: A Journey Unveiled! 🔒 Hey Folks! 🌟...