shell

macosxhints.com - 10.5: Fix the sudo shell prompt Pick of the Week - Apr 21 [Show all picks]Lingon - A GUI tool to create recurring tasks Submit Hint • Search • The Forums • Links • Stats • Polls • FAQ • Headlines • RSS 10,000+ hints and counting! Welcome to macosxhints.com Search: Advanced 10.5: Fix the sudo shell prompt Wed, Mar 19 '08 at 7:30AM PDT • Submitted by lincd0 This hint assumes you are using the default bash shell. If you need to run a series of commands interactively as root (or any other user) using sudo, it's most convenient to start a new shell session with the effective user ID you want by typing sudo -s. Prior to Leopard, you would then get a shell prompt similar to the usual one, but with the effective username in place of your username. For example, if you were logged into host foo.local as user bar, your regular shell prompt would be [foo:~] bar$ ...where the ~ represents your home directory (and it will change to show the current directory). If you started a root shell with sudo -s, the prompt would become... [foo:~] root# ...so you could see at a glance where you were and who you were. Under Leopard, though, the behavior of sudo has changed -- you now get a default prompt with a # to indicate you're running as root -- bash-3.2#. This is much less useful, because now you can't see what host you're logged into or what your working directory is. You have to type extra commands to get that information. To get back the old-style prompt, you need to set the environment variable SUDO_PS1 in one of your shell initialization files. One way to do this is to start a shell (not a sudo shell) and enter... cat >> .profile export SUDO_PS1="\[\h:\w\] \u\\$ " ...then type Control-C to exit the cat process. Close the Terminal window or tab, open a new one, and start a sudo shell. You should now have the old prompt back. To revert the change, edit the file named .profile in your home directory to remove the line you added above. • [3,443 views] Rate this hint: [ 1 · 2 · 3 · 4 · 5 ] Average rating: Hint Options Mail Hint to a Friend Printable Hint Format 10.5: Fix the sudo shell prompt | 19 comments | Create New Account Newest First Oldest First Flat Nested No Comments Threaded Click here to return to the '10.5: Fix the sudo shell prompt' hint The following comments are owned by the person who posted them. This site is not responsible for what they say. 10.5: Fix the sudo shell prompt By: club60.org on Wed, Mar 19 '08 at 8:11AM PDT Or you could issue "sudo su -" command. Reply to This • # 10.5: Fix the sudo shell prompt - By: allanmarcus on Wed, Mar 19 '08 at 9:14AM PDT 10.5: Fix the sudo shell prompt - By: mr_dbr on Wed, Mar 19 '08 at 2:44PM PDT 10.5: Fix the sudo shell prompt - By: leamanc on Thu, Mar 20 '08 at 5:46AM PDT 10.5: Fix the sudo shell prompt By: epyon9283 on Wed, Mar 19 '08 at 9:06AM PDT "sudo -i" will do the same thing Reply to This • # 10.5: Fix the sudo shell prompt - By: allanmarcus on Wed, Mar 19 '08 at 9:18AM PDT Not the same - By: lincd0 on Wed, Mar 19 '08 at 10:01AM PDT 10.5: Fix the sudo shell prompt By: Scaramanga on Wed, Mar 19 '08 at 11:50AM PDT Thank you! This has been bugging me for so long! Reply to This • # 10.5: Fix the sudo shell prompt By: mjb on Wed, Mar 19 '08 at 1:41PM PDT Unix convention in shell prompts is that the trailing character '$' is used for non-root users, and '#' for root (essentially). Reply to This • # 10.5: Fix the sudo shell prompt - By: corienti on Wed, Mar 19 '08 at 5:58PM PDT 10.5: Fix the sudo shell prompt - By: corienti on Wed, Mar 19 '08 at 6:02PM PDT 10.5: Fix the sudo shell prompt - By: mjb on Wed, Mar 19 '08 at 7:37PM PDT The prompt shown does that - By: lincd0 on Thu, Mar 20 '08 at 8:16AM PDT The prompt shown does that - By: mjb on Thu, Mar 20 '08 at 2:53PM PDT 10.5: Fix the sudo shell prompt By: saint42 on Wed, Mar 19 '08 at 4:22PM PDT Personally, I use this setting in .profile: PS1="\u@\h:\w> " This shows me who am I, what machine I am on, and what path: ex: saint@iMac:~> saint@iMac:/System/Library> root@iMac:/goinfre> Reply to This • # Not needed if you are already defining PS1 (+ example) By: ClassicUser on Wed, Mar 19 '08 at 6:10PM PDT To clarify: If you are already defining a custom PS1 entry in such an rc file, it will be picked up by "sudo -s", as well - so this specific "SUDO_PS1" entry would not be needed. FYI, I use a custom entry within my .profile to display the path within brackets - truncating to just the final directory, if the path grows too long (see "MAXPWDLEN"): # set prompt (add brackets to standard prompt) ## default: PS1="\h:\w \u\$ " ## previous: export PS1="[\h:\w] \u\\$ " MAXPWDLEN=21 export PS1='[\h:\ $( MYPWD=${PWD/#$HOME/~} && [ ${#MYPWD} -gt $MAXPWDLEN ] && \ printf "%s" "…${MYPWD/${MYPWD%*/*}/}" || \ printf "%s" "${MYPWD}")] \ \u\$ ' This results in, for example: [mymac:/Users/classic] classic$ …as well as responding to input as: [mymac:/Users/classic] classic$ sudo -s [mymac:/Users/classic] root# cd ~/Library/Application\ Support/ [mymac:…/Application Support] root# cd /System/Library/Frameworks/Message.framework/Versions/B/Resources/English.lproj/ [mymac:…/English.lproj] root# exit [mymac:/Users/classic] classic$ (remember, ellipses are entered via "Option-semicolon"; if these don't work for you, just substitute 3 periods, or the like) Reply to This • # Not needed if you are already defining PS1 (+ example) - By: joshewah on Fri, Mar 21 '08 at 9:06AM PDT Not needed if you are already defining PS1 (+ example) - By: ClassicUser on Sat, Apr 19 '08 at 11:44AM PDT 10.5: Fix the sudo shell prompt By: Zeitkind on Sun, Mar 23 '08 at 3:03PM PDT My prefered one: cat ~/.bashrc alias dir='ls' alias ll='ls -al' export CLICOLOR=1 export LSCOLORS=ExCxhxdxbxegedabaghbag declare -x PS1='\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]' But everyone has its own special .bashrc.. ;) Reply to This • # From our Sponsor... User Functions Username: Password: Don't have an account yet? Sign up as a New User • Lost your password? From our sponsors... What's New: HINTS4 new Hints in the last 1 dayCOMMENTS last 2 days Lossless rotation of JPG images and t... [+2] 10.5: Set up Time Machine on a NAS in... [+4] 10.5: Eject drives and run iSync befo... [+2] Share USB Printer on Mac OS X Server An AppleScript droplet to ease .lit c... 10.5: Reset a user's password in sing... [+7] 10.5: Set any number of recent items 10.4: A fix for non-mounting USB driv... Reach local iTunes library over the net [+4] View PDFs inline in Camino on Intel Macs Watch YouTube videos with QuickTime e... [+8] Use Starcraft on a case-sensitive HFS... Clear msftres and other GPT 'flags' s... Resolve a ssh public key connectivity... [+2] Erase free disk space from the comman... [+15] An assortment of potentially interest... Install Perl module DBD::Oracle on In... [+2] Use launchd to replace folder actions [+11] Wake a sleeping Mac from the network 10.5: Spaces activation made simpler Change the 'after' default paragraph ... 10.5: An iCal/Microsoft Exchange time... Create a Windows bootable CD/DVD with... [+3] Make an external numeric keypad work ... The return of the favorite browser poll! [+9] LINKS last 2 weeksNo recent new links What's New in the Forums? New user script Where is iPhoto's 'Sample Music' stored on HD? Can't empty items in trash?? MUpromo - MenuCalanderClock, DVDremaster, SoundStudio, Parallels +more @ $64.99! Missing 31 GB of Hard Drive disk repair won't (2 parts) Java Preferences utility quit working... OSX - Can my mac have two ip addresses? iPod Notes Firefox phones to home and Google The Editor's Corner... Here are some of my (robg) other projects...• The RobservatoryMy blog - Macs, tech, etc.• Mac OS X Power HoundThe best of Hints in print• Inside iWorkAn iWork training DVD• MacworldColumn, features, online... Hints by Topic -- All Topics --Apps Classic Desktop Desktop Macs Install Internet iPhone iPod Laptop Macs Network OS X Server Other Hardware PDAs etc. Phones Pick of the Week Press Rel Printers Reviews Scanners Site News Storage Devices System System 10.4 System 10.5 UNIX Web Browsers News from Macworld There was a problem reading this feed (see error.log for details). The macosxhints Poll It's that time again -- Browser wars #9. Which web browser is your current favorite? Camino Firefox Flock iCab Internet Explorer Mozilla OmniWeb Opera Safari Shiira IE for Windows via virtualization Other Windows browser via virtualization Other Results 3,574 votes | 52 comments Copyright © 2008 Mac Publishing LLC (Privacy Policy) Contact UsAll trademarks and copyrights on this page are owned by their respective owners. Powered By Geeklog Created this page in 0.20 seconds разделы электросчетчик сэт нужный билет медикаметозное безоперационное прерывание беременность предохранитель пкэ детский гинеколог contiwinterviking купить пекарня бесплатный нард зиплок корпаративные вечеринка купить нипель стелаж пищеблок машина r-600 государственный герб shell сборщик долг бегущий строка комнатный перегородка огнестойкий краска сдать анализ кровь shell