I created a script that prompts users to run the latest macOS update. The script works perfectly when run through a policy, so there are no issues with the overal functionality of the script. The policy is scoped only to Macs that are not yet running macOS 15.4. We have not decided to allow updates to 15.4.1 just yet. I noticed that the policy ran on a Mac running macOS 15.4. It's likely that this Mac had not yet ran a current inventory that would have put it in the macOS 15.4 smart group, which would have excluded it from running the policy. I decided to add a function to the script to check the current installed macOS and then compare it to the required macOS version. If the Mac is already running 15.4 or higher, I want the script to exit without doing anything. The idea is to run this function before doing anything else. If I fill in "15" for "reqosMajor" and "4" for "reqosMinor", this works perfectly. I put this function into a script by itself to test. Each time the function runs using parameters 8 and 9, the values for the two variables expand to nothing. If the values are filled in, the values for the variables work later on in the script when it checks if the required major and minor versions are greater than or equal to the current installed major and minor versions. I used set -x and I can see that the values entered into the parameters are not being passed. I have used parameters in this way for a long time. I don't understand why this is not working. I also tried using parameters 4 and 5. That doesn't work either. What am I doing wrong? Most of my scripts are zsh. I also tried switching to using bash. It had no effect.
macOSVersionCheck() {
# Define variables
local osMajor
local osMinor
local reqosMajor
local reqosMinor
local macOSVersion
macOSVersion=$(/usr/bin/sw_vers | grep "ProductVersion" | /usr/bin/awk '{ print $2 }')
osMajor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}')
osMinor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $2}')
reqosMajor="$8" # Parameter 8
reqosMinor="$9" # Parameter 9
reqOS="${reqosMajor}.${reqosMinor}"
echo "Required macOS version is ${reqOS}"
echo "Current installed macOS version is $macOSVersion"
if [ "$osMajor" -ge "$reqosMajor" ] && [ "$osMinor" -ge "$reqosMinor" ]; then
echo "The current installed macOS version is greater than or equal to the required version. No update needed."
# Stop here. No update is needed.
exit 0
else
echo "The current installed macOS version is less than the required version. Update is needed."
fi
}
