Your WorkWhen you find (Web site layout) a prompt that you d
Your WorkWhen you find a prompt that you d like to keep, youwant to store the $PS1variable somewhere so thatyour prompt returns the next time you log in. Thesafest place to set $PS1is in your ~/.bashrcloginscript. (This script is executed every time you starta new shell.) To save your fancy new prompt: 1.Start your favorite editor (kate, kedit, or theGNOME Text Editor will do). 2.Open the file /home/user-name/.bashrc. Make sure you type in your Linux user nameinstead of user-nameand make sure you includethe period before the word bashrc. Your .bashrcfile will probably look something like this: # .bashrc# User specific aliases and functions# Source global definitionsif [ -f /etc/bashrc ]; then. /etc/bashrcfi3.Add the following code to the end of the file: # Customize the promptBLUE= \[$(tput setaf 4)\] ULINE= \[$(tput smul)\] RESET= \[$(tput sgr0)\] PS1= $BLUE$ULINE[\u@\h]$RESET 4.Now save your changes and close the editor. If you want to change the default prompt for newlycreated user accounts, give yourself superuser privi- leges and modify the /etc/skel/.bashrcfile. /etc/skel/.bashrcis copied to a user s home direc- tory when his or her user account is created. 3.Add the following code to the end the file: function setprompt{ local BLUE= \[$(tput setaf 4)\] local RED= \[$(tput setaf 1)\] local RESET= \[$(tput sgr0)\] # If id u` returns 0, you have# superuser privilegesif [ `id -u` = 0 ] thenPS1= $RED[\u@\h:\W]$RESET elsePS1= $BLUE[\u@\h:\W]$RESET fi} setprompt4.Save your work and close the editor; you refinished! We want to note a couple of interesting points aboutthis sample code: First, you must add this function to the /etc/ bashrcfile, not your own personal ~/.bashrcfile. Why? Because you want to modify theprompt not only for yourself, but also for thesuperuser. (Remember, /etc/bashrcis executedfor all users, and ~/.bashrcis executed onlywhen youlog in.) Second, notice that we created a shell functionand put most of the code inside that function. Bydeclaring the $BLUE, $RED, and $RESETvariablesas local, they re destroyed as soon as the func- tion (setprompt) ends. If you don t wrap the vari- ables inside a function, you ll find them in yourlist of environment variables and probably won- der where they came from. We give some morewords of shell-scripting wisdom in Techniques 8and 10.07
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.