1

Greetings,

I would like to preserve my aliases after sudoing on OSX:

sudo -s
. .profile

Is it possible to achieve this on a SINGLE command line? - i.e. something like:

sudo -s ; . .profile

tks

2
  • I'm pretty sure this is a bash problem. I use zsh and my aliases are kept after doing a sudo -s.
    – wfaulk
    Oct 11, 2009 at 0:16
  • Do sudo -E or sudo -i do anything useful for you? Oct 11, 2009 at 3:08

2 Answers 2

2

Try moving your aliases from .profile to .bashrc. (bash is the default Mac OS X shell now, right?)

1

The easiest way I've found is to modify your sudoers file:

# Defaults specification
Defaults    env_keep += "VISUAL EDITOR"

You can include (or omit) anything you want, placing each of them on an individual line if you'd like.

Here's the default Leopard sudoers env_keep list:

# Defaults specification
Defaults    env_reset
Defaults    env_keep += "BLOCKSIZE"
Defaults    env_keep += "COLORFGBG COLORTERM"
Defaults    env_keep += "__CF_USER_TEXT_ENCODING"
Defaults    env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
Defaults    env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
Defaults    env_keep += "LINES COLUMNS"
Defaults    env_keep += "LSCOLORS"
Defaults    env_keep += "SSH_AUTH_SOCK"
Defaults    env_keep += "TZ"
Defaults    env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults    env_keep += "EDITOR VISUAL"

You must log in to answer this question.

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