Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I am working on our RHEL machines, I use sudo su - to switch to being root. One day, a typo meant I typed sudo su -- instead - it seems to me that everything was the same as with a single hyphen, except that I was in the same folder as before I issued the command (with a single hyphen I find myself in /root).

Are there other differences? Is it safe to use this in scenarios where I know I want to work in the same directory?

share|improve this question
add comment

1 Answer

When you provide a double-hyphen the experience you will have is identical to if you had just executed sudo su without any hyphen.

Passing a single hyphen is identical to passing -l or --login. The man page for su describes the behavior as:

Provide an environment similar to what the user would expect had the user logged in directly.

This includes setting your directory to your home directory and setting a bunch of other environment variables.

Passing a double-hyphen to a command is typically used to mark the end of command-line flags and the beginning of non-flag arguments. For example, if you run touch -R you'll receive an error saying that -R is not an option to touch, but if you run touch -- -R it will create a file named -R. This is true of many command-line tools (ls -R will do a recursive ls whereas ls -- -R will perform an ls on a file or directory named -R.

So, to wrap this up, when you pass -- to su it is basically ignoring the -- and acting like you didn't pass any option at all.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.