0

To calculate $1*$1*$1

#!/bin/bash

volume=$1*$1*$1
echo "The volume of the cube is"$volume

In terminal, it shows enter image description here

How can I fix this?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    Please don't post images of text. Use the _select_ then the _copy_ functionality provided by your OS and then _paste_ the text in the question. Use the `{}` button in the toolbar of the question editor to format it nicely. – axiac Mar 05 '21 at 16:22

1 Answers1

1

Use $(( )) to evaluate arithmetic expressions in bash.

volume=$(($1 * $1 * $1))

You can also use the let command:

let volume=$1*$1*$1

or you can use (( )) to execute an arithmetic statement

((volume = $1 * $1 * $1))

What you wrote was being treated as a filename wildcard.

You also need to provide an argument to the script, this will be used as $1.

$ bash testarith.sh 5
The volume of the cube is 125
Barmar
  • 741,623
  • 53
  • 500
  • 612