Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA249      CA318      CA425      CA651

w2mind.computing.dcu.ie      w2mind.org


Configuration files



.profile / .login

Runs once, when you log in.
Like AUTOEXEC.BAT on DOS.
Can call a shell script in here.


How to change the PATH

  1. Make a $HOME/bin directory to hold your own programs
  2. Edit .profile
  3. put $HOME/bin and maybe current dir (.) in $PATH.
    Add one of these (not all of them) to .profile:
    
    # add $HOME/bin  
    export PATH=$PATH:$HOME/bin
    
    # add .
    export PATH=$PATH:.
    
    # add both
    export PATH=$PATH:$HOME/bin:.
    
    
  4. Logout of Linux and back in again.
  5. echo $PATH
    to see that $HOME/bin is in it.
  6. Now your own programs in $HOME/bin can be called at any time on the command line


Do not over-ride system program names

Type "which ls" to see the location of the system ls program.
If you write your own "ls" script, and insert it in a directory in the path which comes before that system directory, then you have over-ridden the system ls.
All calls to "ls" at the command-line will be calls to your program, not system ls.

This may be ok for you, but other programs that call ls will now be calling your version instead.
They may fail in unexpected ways.

Recommended:

  1. Put . and your own dirs at end of PATH, not start
  2. Do not use system command names. Do "which scriptname" before choosing a script name to make sure it does not already exist.

"." in the PATH can be a security risk

Why?

Also, if you are in someone else's directory, and read is off and "." is in the PATH, you will find strange effects.





.bashrc / .cshrc

Run for every shell instance (e.g. shell script)

Beware recursion: Do not call a shell script in here.


How to set up aliases

Text substitutions at the command line.

In .bashrc:

alias name="string"

alias h='history'

alias cdshare="cd $HOME/share"

In .cshrc:
alias name string


For instance (on C shell):

If you regularly need to login to some other server, put the following in .cshrc:
  alias t 'ssh -l userid remoteserver'
and then, to connect to it, just type:
  t
Or if you regularly need to jump to your web directory, put the following in .cshrc:
  alias cdp 'cd $HOME/public_html'
and then, any time you want to jump to that directory, just type:
  cdp


This straight text substitution at the command-line is more efficient than starting up a Shell script that needs parameters set up for it (environment variables, command-line arguments) and then needs to be interpreted.
It is like the difference between a macro text substitution (e.g. a #define in C/C++) and a run-time procedure call.

In fact, in the case of "cdp" above, a Shell program won't work since a Shell program can't change the directory of the parent process that called it.


How to change the prompt

Edit .bashrc


# PS1='[\H] [\u] [\w] > '

PS1='\W> '  

See:


Feeds      HumphrysFamilyTree.com

Bookmark and Share           On Internet since 1987.