Reputation: 4636
running - ./bashfile.sh a 1 1
#!/bin/bash
addit () {
echo $(($2 + $3))
}
if [ $1 == a ]
then
addit
fi
produces
syntax error: operand expected (error token is "+ ")
What is causing this problem?
Thanks
Upvotes: 0
Views: 227
Reputation: 2363
You should call your addit
function in the script, something like: addit $1 $2
, after the definition of addit
.
#!/bin/bash
addit () {
echo $(($1 + $2))
}
addit $1 $2
Running:
chmod +x bashfile.sh
./bashfile 1 1
2
Upvotes: 2