School of Computing. Dublin City University.
Online coding site: Ancient Brain
coders JavaScript worlds
In general, how to pass information to a program:
$HOME/.mozilla/firefox/id/prefs.jsand on Windows:
C:\Program Files\Mozilla Firefox\defaults\pref\firefox.js
$ var=value command args
bash manual: "A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator."
The variable has that value inside the command, but does not retain the value in bash after the command exits.
See what is installed:
ls -l /bin/*shOn DCU Linux, something like:
-rwxr-xr-x 1 root root 1168776 Apr 18 2019 /bin/bash -rwxr-xr-x 1 root root 121464 Jan 17 2019 /bin/dash lrwxrwxrwx 1 root root 4 Apr 18 2019 /bin/rbash -> bash lrwxrwxrwx 1 root root 3 Feb 5 2019 /bin/rzsh -> zsh lrwxrwxrwx 1 root root 4 Jan 17 2019 /bin/sh -> dash -rwxr-xr-x 1 root root 861568 Feb 5 2019 /bin/zsh
To start using one as the command-line, just type its name.
"exit" to return.
The first line
of a shell script
should state which shell
it is to run in, using syntax like:
#!/bin/shellname
This is called a "shebang" line.
For example:
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.
x=3 export x echo "prog1 [$x]" prog2
calls 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:
redo
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.