|
|
Using The Shell VISummary:
bash Configuration FilesWhen you do a ls .bash* in your home directory, you will see a list of files:
These files define per user settings. System wide settings are stored in '/etc/profile', '/etc/bashrc' and the files in '/etc/profile.d'. You should prefer using the per user configuration files, though: editing them doesn't require you to be 'root', and they also allow you to set up things differently for 'root' and each user account, which can be a good thing. In case of conflicts between user settings and system settings, user settings prevail. The PromptThe prompt is the first thing you see every time you open a console or an xterm. It looks like this: account@hostname ~ $ In its default setting it shows your user name, the hostname of your machine (or 'localhost' is you haven't assigned one) and the current working directory ('~' is the Unix shortcut for your home directory). You can set or change your prompt via changing the content of the $PS1 variable. The command echo $PS1 displays the current setting. Available special characters and their meaning are listed in man bash, section PROMPTING. Need some ideas on what might be a better prompt? Well, for starters the default setting isn't very friendly to forgetful people, since it only shows the last part of your current path. If you see a prompt like tom@localhost bin $ your current working directory could be '/bin', '/usr/bin', '/usr/local/bin' or '/usr/X11R6/bin'. Sure, you can type pwd ('print working directory') to find out where you are, but shouldn't there be a way to tell the shell to do that on its own accord? Parameters are described in man bash, chapter 'PROMPTING'. You can add nifty things like the current time in different formats or the history number of the command, even different colors are possible. My currently favored setting in my user '~/.bashrc' is: PS1="PS1="[033[1m][w][033[0m] "
'root's ~/.bashrc has: PS1="[033[0;31m][w][033[0m] "
And the prompt I get, is this: [/usr/bin] And this when I'm 'root': [/usr/bin] I've chopped the host- and user name part, since I have no need for it. But I want to see at first glance if I am logged in as a user or as 'root' on this console. Note that the user prompt will be white on dark backgrounds and black on light ones. A more moderate setting might be PS1="u: w\\$ " which will result in prompts like these: user_name: /usr/bin$ but who cares about being moderate? :-) You can test various settings on the fly by using the export export PS1="u: w\\$ " You may even 'theme' your prompt, i.e. use different colors or make it look like an good ol' C64 prompt. If you are interested in this, have a look at Bashish . Changing $PATH'$PATH', like '$PS1', belongs to the group of environment variables. Type set to get a full list of all currently defined environment variables. You shouldn't temper with the settings of most these variables unless you know what you are doing and why. Knowing how to change the $PATH variable, however, can be useful, since it determines the names of directories where the shell looks for commands and programs, i.e. for executable files. If the command you want to run is in a directory which is listed in $PATH, you do not need to supply the full path to that command, just the command name. Some third-party software does not install its executable files into the standard Linux directories for commands and programs. Adding their non-standard installation locations to the $PATH is a possible workaround. Furthermore it will also teach you how to deal with environment variables in general. First off you have noticed that the names of environment variables are written in all capital letters. This is just a convention, but since Linux discriminates between capital and small letters, it is important to keep that in mind. You can define a variable like '$path' or '$pAtH', but the shell won't use it. PATH=/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin to access the variable and its value, you need to put the '$' in front of it: echo $PATH because otherwise, the variable name is treated as a simple text string: echo PATH The third item is especially important for dealing with the $PATH variable. You can not only replace variables, but also just add new strings to their values. Most of the time, you don't want to do something like 'PATH=/some/directory' because that would erase all the other directories from your $PATH and force you to supply the full path name to every command you want to run on that terminal. Instead, just add it: PATH=$PATH:/some/directory Here PATH is set to its current value (represented by $PATH), plus one more directory. So far, you've only set a $PATH variable for the terminal you have typed that command in. If you open a new terminal and issue a echo $PATH, you will see the old $PATH without the directory you just added. You have defined a local environment variable (restricted to the terminal you defined it in). export PATH=$PATH:/some/directory If you now open a new terminal and type echo $PATH, you will see the new value of $PATH in this terminal, too. Notice, however, that the 'export' command only sets or changes variables for the terminal it is run in and terminals which are started after it has been run. Terminals which were already open will still have the old $PATH. In order to add a directory permanently to your $PATH, just add the above 'export' command line to your '.bash_profile'. The last page of this article will introduce two more advanced configuration methods and a FAQ dealing with minor configuration and error message issues. |