How to Do Multiplication in Linux Scripts

The Linux script or shell script is the simple programming language supported by Linux command interpreters. The command interpreter, for example Bash, processes commands entered by a user. The shell script is a text file that contains a list of commands that Bash executes. Multiplication is a common mathematical operation that you may need to use in your script.

Instructions

    • 1

      Add the following line on the top of your script file to indicate that this is linux shell script:
      #!/bin/bash

    • 2

      Define variables you need to multiply; for example
      variable1 = 25
      variable2 = 12

    • 3

      Make the multiplication and assign the result to the variable "product."
      product=$[$variable1*variable2]

    • 4

      Print out the product from your script to verify the output:
      echo the multiplication result is $product.
      In this example, the script output is "the multiplication result is 300."

Related Searches:

References

Comments

Related Ads

Featured