Reading Data into Variables

You can store data into a variable from one of the following sources:

  • Assigning a value in the script using the equal sign (=). This method is discussed in the previous section.

  • Storing the output of a command using back ticks (`).

  • Passing the information on the command line when starting the script.

  • Prompting the user to enter data with the read command.

This section describes how to read data into variables using these methods.

The previous section discussed assigning simple values using the equal sign. You can also store arithmetic calculations in a variable using the let command, as follows:

let sum=3+4
let total=total+1
let sum=$n1+$n2-3

You can add (+), subtract (-), multiply (*), or divide (/). You can use modulus ...

Get Spring Into Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.