Get current username in Julia (Linux)

I have to do something stupid, but I cannot find the current username using Julia. The closest function in Base looks like gethostname() , but returns the computer name, not the username. I tried system calls, but I'm having problems due to the $ interpolation character. In particular, although echo $USER returns the corresponding username in the terminal when I try to do the following in Julia, I get various errors or incorrect answers:

 run(`echo $USER`) run(`echo "$USER"`) run(`echo '$USER'`) run(`echo '$'USER`) run(`echo \$USER`) 

I think the problem is that Julia misinterprets $ as interpolation, but I have no idea how to get around this.

Any ideas?

+5
source share
1 answer

Easy workaround:

 run(`whoami`) 

But not necessary, as this works:

 ENV["USER"] 
+7
source

Source: https://habr.com/ru/post/1210517/


All Articles