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?
run(`sh -c 'echo $USER'`)
would have worked (but the accepted answer is far better!) – Lillylillywhite