I must be doing something stupid, but I can't seem to retrieve the current username using Julia. The closest function in Base
appears to be gethostname()
, but that returns the computer name, not the username. I tried system calls but am having trouble due to the interpolation character $
. Specifically, although echo $USER
returns the appropriate username in a terminal, when I try 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 guess the issue is that Julia
is misinterpreting the $
as an interpolation, but I've got no idea how to get around this.
Any ideas?
An easy workaround:
run(`whoami`)
But unnecessary, as this works:
ENV["USER"]
This works on both Linux and Windows:
splitdir(homedir())[end]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With