School of Computing. Dublin City University.
Online coding site: Ancient Brain
Often instructions can be put in multiple places and you may not notice the difference, depending on how you work.
Run at login to GUI and/or login shell (e.g. ssh):
file Hierarchy notes /etc/profile OS /etc/profile.d/* OS directory of scripts to run
see code in /etc/profile
/etc/profile.local Local Local install to extend /etc/profile ~/.profile Personal ~/.bash_profile Personal bash specific
Run for interactive shell that is not login shell (e.g. new terminal in GUI):
file Hierarchy notes /etc/bash.bashrc OS bash specific /etc/bash.bashrc.local Local Local install to extend /etc/bash.bashrc
~/.bashrc Personal bash specific
Run for non-interactive shell (e.g. shell script):
file Hierarchy notes $BASH_ENV Can point to any file.
Not set up in DCU install by default.
Beware of infinite loops!
Q. How could there be an infinite loop?
Explore yourself: Add instructions to these files and see where they are executed.
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.
Also, if you are in someone else's directory, and read is off and "." is in the PATH, you will find strange effects.
In .cshrc:alias name="string" alias h='history' alias cdshare="cd $HOME/share"
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:tOr 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.
See:# PS1='[\H] [\u] [\w] > ' PS1='\W> '