Tuesday, December 14, 2010

How to get current user name in Bash script

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"

2 comments: