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"

3 comments:

  1. #!/bin/bash

    # Keep it simple
    whoami

    ReplyDelete
  2. Present a perfect duplicate of your content available to be purchased, with your name and contact data conveniently imprinted on the cover. screenplay analysis

    ReplyDelete