Just started doing basic shell scripting need some help with adding number for example 6 9 -4 2 with add command
#!/bin/bash
function add() {
sum=`expr $a + $b + $c + $d`
echo "$sum"; }
read a b c d
add
fi
Just started doing basic shell scripting need some help with adding number for example 6 9 -4 2 with add command
#!/bin/bash
function add() {
sum=`expr $a + $b + $c + $d`
echo "$sum"; }
read a b c d
add
fi
Aside of the "fi" at the end of your script (likely a copy-and-paste error?), the script looks correct, although it can be done easier: bash already has the capability to do calculation, so you don't need to create a child process by invoking expr:
echo $((a+b+c+d))
would also output the sum.