Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 '09 at 0:16
    
Do sudo -E or sudo -i do anything useful for you? –  Dennis Williamson Oct 11 '09 at 3:08

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer

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"
share|improve this answer

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.