Reputation: 445
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
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
Reputation: 23364
Use a bash arithmetic context for your comparison
if (( $# == $minNumOfParams + 1 )) ; then
Upvotes: 2