8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

sudoしたときに元のUser名を取得する

Last updated at Posted at 2014-06-25

sudoを使ってシェルスクリプトを走らせた時、
echo $USERとするとrootが返ってしまいます。

rootではなくシェルを走らせた元々のUserを取得したい場合、
echo $SUDO_USERのように$SUDO_USERを利用すればいいそうです。

参考:
http://stackoverflow.com/questions/4598001/how-do-you-find-the-original-user-through-multiple-sudo-and-su-commands

8
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?