Get current user name in a bash script

posted by Matt Adams

Using /usr/bin/whoami command

#!/bin/bash
echo "$(whoami)"

Using /usr/bin/id command

#!/bin/bash
echo "$(id -u -n)"

Using USER environment variable

#!/bin/bash
echo "$USER"