Create a shell script called /home/bob/calculate-price.sh
and it must accept 2 numbers as command line parameters $1
and $2
. It must print the product (multiplied value) of the numbers as output. But this time in a new format - The total price for items is 1000 dollars
I can solve it if I am using read for two variables, but I want to understand the buil in variable solution for this problem
Simplest form. Note I am not looking at the question, because you didn’t give a link to it, but this program prints the product of the two command line arguments.
#!/usr/bin/bash
echo "The total price for items is $(($1 * $2)) dollars"
And run it
/home/bob$ ./calculate-price.sh 10 100
The total price for items is 1000 dollars
/home/bob$
And with different arguments…
/home/bob$ ./calculate-price.sh 2 500
The total price for items is 1000 dollars
/home/bob$