School of Computing. Dublin City University.
My big idea: Ancient Brain
In general, how to pass information to a program:
See what is installed:
ls -l /bin/*shOn DCU Linux, something like:
-rwxr-xr-x 1 root root 656584 Oct 10 2014 /bin/bash lrwxrwxrwx 1 root root 4 Feb 12 2014 /bin/csh -> tcsh lrwxrwxrwx 1 root root 21 Feb 12 2014 /bin/ksh -> /etc/alternatives/ksh -rwxr-xr-x 1 root root 146512 Sep 28 2013 /bin/sash lrwxrwxrwx 1 root root 4 Oct 21 2014 /bin/sh -> bash -rwxr-xr-x 1 root root 387184 Oct 23 2013 /bin/tcsh lrwxrwxrwx 1 root root 12 Nov 25 2014 /bin/zsh -> /usr/bin/zsh
To start using one as the command-line, just type its name. e.g.
csh"exit" to return.
The first line
of a shell script
should state which shell
it is to run in, using syntax like:
This is called a "shebang" line.
Can have endless number of interpreters of source text. Can invent your own.
But you cannot depend on this
- exactly what happens depends on each system.
Your shell scripts may not be portable to different UNIX-family systems.
So it is good practice to define the shell in the first line.
HOME=/users/gdf1/mhtest09 OSTYPE=linux PATH=/users/gdf1/mhtest09/bin:/usr/local/bin:/usr/bin:/bin:.... PWD=/users/gdf1/mhtest09/bin SHELL=/bin/bash USER=mhtest09 USERNAME=mhtest09 http_proxy=http://wwwproxy.computing.dcu.ie:8000 no_proxy='localhost, 127.0.0.1, dcu.ie'
cwd /users/gdf1/mhtest09 home /users/gdf1/mhtest09 path (/users/gdf1/mhtest09/bin /usr/local/bin /usr/bin /bin ....) shell /bin/tcsh user mhtest09
if test $1 = ""
x=3 export x echo "prog1 [$x]" prog2
echo "prog2 [$x]"
Try it with and without export.
export will make variable x available to a script called by this script, and any scripts called by that script, etc., without any further exporting needed. Only a single export statement is needed (in the top parent script).
It would be quite an overhead
to search all the directories in the PATH
every time you type a command.
So some (all?) shells make a list of executable files in these directories (with the exception of ".") once, at login, or at the start of running a script, and then the shell caches that list in memory for future use.
This can cause some problems. e.g. You add a new program to your $HOME/bin directory, which is in the PATH. You then type the name of the program and it is not recognised. The solution is you need to re-build the cache.
source .FILEwhere .FILE is the config file where the path is defined.
If you do this a lot, you might like to put the following alias in .bashrc:
alias redo="source $HOME/.bashrc"or .cshrc:
alias redo source $home/.cshrcAnd then, every time your PATH cache is out of date, you type:
On bash, in .bashrc:
export CDPATH=$HOME:$HOME/public_htmlOn csh, in .cshrc:
set cdpath = ( $home $home/public_html )
Q. Do you need "." in the CDPATH as well?
If you have defined "cdpath" like above, then wherever you are on the disk, you can jump direct to a subdirectory off your home directory or off your web directory by just typing "cd (subdirectory)".
Other tools for jumping around disk:
Using tools like this, jumping around the disk and performing tasks on the command-line can actually be quicker than doing it through the File Manager.
csh: echo '\0nn' echo char by octal numeric code echo '\0nnn' echo "\0115" echo "M" echo "\0275" echo "½" bash: echo -e (string)
ExerciseThe above echo syntax works on csh on DCU Linux.
Get this script working on csh on DCU Linux: Script to build list of chars