I am using getopt in a bash script that works fine on Linux. However, when it is executed on AIX, the output is not the same:
AIX output
TEMP=$(getopt -o d:hi: --long database:,help,instance: -n ${APPL_NAME} -- "${@}")
getopt -o d:hi: --long database:,help,instance: -n ${APPL_NAME} -- "${@}"
++ getopt -o d:hi: --long database:,help,instance: -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv
+ TEMP='-- d:hi: --long database:,help,instance: -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv '
Linux output
TEMP=$(getopt -o d:hi: --long database:,help,instance: -n ${APPL_NAME} -- "${@}")
getopt -o d:hi: --long database:,help,instance: -n ${APPL_NAME} -- "${@}")
getopt -o d:hi: --long database:,help,instance: -n ${APPL_NAME} -- "${@}"
++ getopt -o d:hi: --long database:,help,instance: -n nagios -- -i /home/db2inst1 -d sample
+ TEMP=' -i '\''/home/db2inst1'\'' -d '\''sample'\'' --'
As you can see, the values in TEMP are not valid in AIX, and the script cannot continue.
Why is the reason of this problem? how can it be solved?
This is for an open source script hosted at: https://github.com/angoca/monitor-db2-with-nagios/blob/master/check_database_connection