Quantcast
Channel: Environment Variable for Username - Ask Ubuntu
Viewing all articles
Browse latest Browse all 5

Answer by Arronical for Environment Variable for Username

$
0
0

The Linux version environment variable to refer to the current user is USER.

To get the output you'd like to see use $USER in your command:

echo $USER

And to use it in another string such as a path:

/path/with/$USER/in/it

Will expand the username within the string. Though you should protect variable expansions with curly braces when a variable is directly next to other characters. It's not so important in this example as the USER variable is bounded by non-alphanumeric characters, but would be important in the following case:

/path/to/${USER}directory

(Thanks to ByteCommander for the tip in comments)

Another useful one to know is $HOME for the user's home directory.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>