spyke01
spyke01

Reputation: 445

Addition in Conditional in Bash

I am trying to check for optional parameters within the flow of a bash script but keep getting an error. This is the code I am trying to use:

# Do additional database import if needed
if ( $# == ( $minNumOfParams + 1 ) ) ; then
    mysql -u $newDBUsername -p$newDBPassword $newDBName < $databaseExport2
fi

The error I am getting is:

/bin/bash: line 27: syntax error near unexpected token `('
/bin/bash: line 27: `   if ( 13 == ( 12 + 1 ) ) ; then'

How do I fix this?

Upvotes: 0

Views: 66

Answers (2)

zjhui
zjhui

Reputation: 809

i think you may should try the following :

if [[ $# -eq $minNumOfParams+1 ]]; then mysql -u $newDBUsername -p$newDBPassword $newDBName < $databaseExport2 fi

Upvotes: 0

iruvar
iruvar

Reputation: 23364

Use a bash arithmetic context for your comparison

if (( $# == $minNumOfParams + 1 )) ; then

Upvotes: 2

Related Questions