scutil is an app that can be used to get and set the ComputerName of your Mac. The following command will return with the name of your computer.
scutil –get ComputerName
Now, if you want to change the name then you would use –set. So if you wanted to set the name of your computer to kryptedmacbook you would use the following command:
scutil –set kryptedmacbook
Now, let’s say you’re writing a shell script and you want to put the computer name in a variable (let’s just call it computernm). You could use the following line:
computernm=`scutil –get ComputerName`
Happy Scripting!