Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    Your question seems to center around the name of the subdirectory under /media. The script determines this by invoking either media_dir=/media/$USERNAME/ or media_dir=/run/media/$USERNAME/. What is the $USERNAME you're expecting, and what is the $USERNAME you're getting instead? Have you created a simple test script to test the value of $USERNAME when you invoke the script via sudo script-name vs. something like sudo -i script-name? Have you looked in the sudo man page or other docs to see what makes sudo change that variable? Commented Dec 19, 2022 at 19:25
  • 1
    +1 afaik USERNAME is not a "standard" environment variable and is unlikely to be preserved under the default Ubuntu sudoers env_reset policy Commented Dec 19, 2022 at 19:46
  • @SottoVoce why sudo script vs sudo -i script instead of sudo script vs script? In what case would the sudo -i be different? If there were something in root's bashrc or profile that set the variable? Or is there something else? Commented Dec 19, 2022 at 21:10
  • @steeldriver Wow, this is a palm to the face moment. You are absolutely correct. $USERNAME will not be preserved in either Arch or Ubuntu environments when running in pseudo. I need to re-architect the script to account for that. Commented Dec 19, 2022 at 21:24
  • @terdon yes, in case something in this machine's .profile, .bash_profile, or .login scripts sets $USERNAME (though it's more often $HOME that catches people invoking scripts via sudo). My emphasis was more on the something like than on sudo -i. Commented Dec 19, 2022 at 21:41