I've made something that I think ought to be a shell script called bashispainful.sh:
Code:
#!/bin/bash Var1= $((10*5)) Var2= $((10/5)) Var3= $((10-5)) Var4= $((10+5)) Var5= ($(Var4)*$(Var3)) echo $Var1 echo $Var2 echo $Var3 echo $Var4 echo $Var5 I would like to receive the output:
50 2 5 15 75 My current output:
./Bashispainful.sh: line 2: 50: command not found ./Bashispainful.sh: line 3: 2: command not found ./Bashispainful.sh: line 4: 5: command not found ./Bashispainful.sh: line 5: 15: command not found ./Bashispainful.sh: line 6: syntax error near unexpected token `(' ./Bashispainful.sh: line 6: `Var5= ($(Var4)*$(Var3))' My aim here is to get any kind of grip on being able to do basic maths in bash. I have tried every website and every combination of brackets, dollar signs and lack thereof that I can think of and frankly I am baffled and desparate. How can I perform simple maths in bash?
(Please make this easy to understand - please assume that I am a non-programmer and stupid)
((...))arithmetic form, in which variables don't need to be prefixed with a$(unless they are positional parameters like$3) and spaces don't matter. For example:(( a = 42 , b = a - 27))