getopt utility in macOS is not respecting or not allowing space character while passed with a string argument.
Below is sample script
#!/bin/bash
TEMP=$(getopt -n "$0" -a -l "project:" -- -- "$@")
[ $? -eq 0 ] || exit
eval set -- "$TEMP"
while [ $# -gt 0 ]
do
case "$1" in
--project) PROJECT="$2";;
--) shift;;
esac
shift;
done
echo $PROJECT
Now when we run this script code in macOS (which has z-shell as command line interpreter) we saw string part after space character is missing.
Script Run
./test.sh --project "testing app"
Result-coming
testing
Expected Output
testing app
While the same script code run in Linux/Unix OS is giving expected outcome either with bash shell or sh shell or zsh shell command line interpreters.
So why getopt is behaving like this in macOS for this piece of code?