lundi 22 décembre 2014

Bash script if statement not working

I'm trying to write a script that adds three specified arguments together, and if there are no arguments outputs: "No arguments".


The trouble is that "No arguments" is always output even when there are three arguments.


I am very new to shell script.


Here is my script:



#!/bin/sh
if [[("$#"==0)]]; then
echo "No arguments specified"
exit 1
fi


sum=0
sum=$(expr $1 + $2 + $3)
echo "$sum"
exit 0

Aucun commentaire:

Enregistrer un commentaire