Why my MacBook Air terminal uses sh-3.2# instead of my username#?

Solution 1:

I don't know why it changed, but you can override sh-3.2# or other default shell prompts by changing the $PS1 variable. To do that, simply run the following command (including the space after the dollar sign):

export PS1='\h:\w \u\$ '

This will replace your shell prompt with Zoos-MacBook-Air:~ root$. However, this change is not persistent and will be gone when you exit or close the Terminal. You can make it persistent by editing root's .bash_profile file. Run the following command while you are in a root shell to modify that file:

echo 'export PS1='"'"'\h:\w \u\$ '"'" >> ~/.bash_profile
echo 'export PS1='"'"'\h:\w \u\$ '"'" >> ~/.profile

or

echo "export PS1='\\h:\\w \\u\\\$ '" >> ~/.bash_profile
echo "export PS1='\\h:\\w \\u\\\$ '" >> ~/.profile

This will make the change persistent.

Tests were made on iOS 11 with root shell, but everything in this answer works on macOS as well.