Get current username in Julia (Linux)
·
Answer a question
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?
Answers
An easy workaround:
run(`whoami`)
But unnecessary, as this works:
ENV["USER"]
更多推荐

所有评论(0)