This is just a minimal example. Better check the manual page of getopt and study the example script linked by r-senior above to understand how getopt works.
Code:
script="compiled-bash.sh"
temp=`getopt -l id:,name:,address:,type: -n "$0" -- '' "$@"` || exit 1
eval set -- optname optval "$temp"
declare -A opt
while shift 2; do
case $1 in
--id|--name|--address|--type) opt[${1#--}]="$2";;
esac
done
cat <<EOF >"$script"
#!/bin/bash
SERVER_ID=${opt[id]}
SERVER_NAME=${opt[name]}
SERVER_IP=${opt[address]}
SERVER_TYPE=${opt[type]}
EOF
Bookmarks