user1043279
user1043279

Reputation:

Using $USER in scripts

Given a script which sets some arbitrary properties on a dev server, if I wanted to automatically insert the users system name into a path for say log files, how would I go about doing so?

desired output:

/usr/user/logs/log_file

I have tried using whoami, echo whoami, echo $USER, and it fails to give the desired output. Any help would be greatly appreciated.

Upvotes: 0

Views: 76

Answers (1)

hek2mgl
hek2mgl

Reputation: 158030

$USER should work. Like this:

log_file="/usr/$USER/logs/log_file"

however, whoami will work too:

log_file="/usr/$(whoami)/logs/log_file"

Upvotes: 1

Related Questions