Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Modular profile file for your shell UNIX
This tip is a shell setup technique that I have stolen from Mandrake Linux. It is only good for people that have heavilly customized their /etc/profile file, so the instructions assume a good deal of terminal knowledge. Instead of having one, monolithic profile file that is littered with different commands and environment settings, you can modularize it into a bunch of tidy, discrete items. You can do this as follows:
  1. su to root and cd to the /etc directory.

  2. Create a directory in /etc called profile.d.

  3. Use your favorite console text editor to add the following lines to the beginning of your profile file:
    for PROFILE_SCRIPT in $( ls /etc/profile.d/*.sh ); do
    . $PROFILE_SCRIPT
    done
  4. Convert all of the commands in your profile file to individual shell scripts, and save them in /etc/profile.d (make sure they end in .sh), and delete them from /etc/profile.
Voila! Instead of having one, confusing, hard to navigate profile file, you have tidy, individual scripts. For example, my alias for ll (I use bash, so that ll is not built in) is in /etc/profile.d/alias_ll.sh, and my prompt code is in /etc/profile.d/prompt.sh.
    •    
  • Currently 3.67 / 5
  You rated: 2 / 5 (3 votes cast)
 
[8,096 views]  

Modular profile file for your shell | 2 comments | Create New Account
Click here to return to the 'Modular profile file for your shell' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
whats a profile do?
Authored by: Hes Nikke on Dec 24, '01 05:13:22AM

what does a profile do and how does it help me?



[ Reply to This | # ]
whats a profile do?
Authored by: dlandrith on Jan 04, '02 09:55:02PM
The /etc/profile or ~/.profile file are read whenever a shell is invoked. It is typically used to set environmental variables like PATH (where to look for commands), MANPATH (where to look for man pages), PS1 (main prompt), PAGER (what to use for man), and any other variables that you may want to add that are specific to your environment (i.e., CLASSPATH, LDFLAGS, EDITOR, HSTSIZE, and CFLAGS are examples of regular, but less common environmental variables). If you are using tcsh (the default shell for OS X), try typing man tcsh. You will get a 40 to 60 page document that will explain all this and more. If you don't mind staying up all night, it's not a bad read.

[ Reply to This | # ]