Change MacOS Computer name with User Interaction Prompt

#!/bin/bash

computerName=$(osascript -e 'set updateUserName to text returned of (display dialog "Enter the computer name" buttons {"Cancel", "OK"} default button "OK" default answer "")')

sudo scutil --set HostName "$computerName"
sudo scutil --set LocalHostName "$computerName"
sudo scutil --set ComputerName "$computerName"