Quick Answer: How Do You Add Numbers to a File in Linux?
Contents

How do you add numbers in Linux?

Use the following syntax to calculate the sum of two integers in a shell script:

  1. Using expr command with quotes sum=`expr $num1 + $num2`
  2. Use expr command inclosed with brackets and start with dollar symbol. sum=$(expr $num1 + $num2)
  3. This is my preferred way to directly with the shell. sum=$(($num1 + $num2))

How do you add values to a file in Linux?

You need to use the >> to append text to end of file. It is also useful to redirect and append/add line to end of file on Linux or Unix-like system.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest