I wrote a function in bash script. However, it’s complaining about syntax. I really can’t see what is it….. the error message is [: missing `]’
addem() {
if [ $# -eq 0] || [ $# -gt 2 ]
then
echo -1
elif [ $# -eq 1 ]
then
echo $[ $1 + $1 ]
else
echo $[ $1 + $2 ]
fi
}
You need a space before the first
]. That is:change:
if [ $# -eq 0] || [ $# -gt 2 ]to:
if [ $# -eq 0 ] || [ $# -gt 2 ]