1

What is the difference between the following su commands?

su -m
su -p

I know that both flags are used to preserve the current environment but I don’t know the differences if there are any.

1 Answer 1

2

There are no differences, they are just different options for the same behaviour. They probably come from different older versions of su that implemented one of these options with the same behaviour.

From the man page:

 -m, -p, --preserve-environment
     Preserve the current environment, except for:

     $PATH
         reset according to the /etc/login.defs options ENV_PATH or
         ENV_SUPATH (see below);

     $IFS
         reset to “<space><tab><newline>”, if it was set.

     If the target user has a restricted shell, this option has no
     effect (unless su is called by root).
5
  • Actually I observed some differences using different flags (m or p). I have a script which behaves differently if I use -m than if I use -p.
    – Vombat
    Jun 11, 2013 at 19:31
  • And your man page says it is the same? What version of su? On which system? Does su --help give an difference for the two?
    – Anthon
    Jun 11, 2013 at 19:33
  • I don’t have access to the system now. Tomorrow I will check the su version etc.
    – Vombat
    Jun 11, 2013 at 19:35
  • Ok, my information is from Ubuntu 12.04
    – Anthon
    Jun 11, 2013 at 19:36
  • @Anthon: There is no man page available in the linux version I am using but according to --help output it says "-m, --preserve-environment do not reset environment variables -p same as -m". And the linux version I am using is: SUSE Linux Enterprise Server 11 SP2.
    – Vombat
    Jun 12, 2013 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .