Shells

From Mu2eWiki
Revision as of 22:24, 20 September 2021 by Rlc (talk | contribs)
Jump to navigation Jump to search

We use the bash linux shell exclusively for the interactive command line and shell scripting. In general, this is the most powerful shell and the professional's choice.

Setup scripts

The Mu2e computing environment, and its documentation, presume that you setup UPS in your login scripts. See below for recommended login scripts.

We strongly recommend you not setup UPS packages (other than UPS itself) in your login scripts. Experience has shown that this will sometimes interfere with the correct operation of Mu2e software.

When you first get a Mu2e computing account we recommend that you copy these two example files to your home directory:

  • Example ~/.bash_profile
    • This file is executed at the start of each login shell.
    • It sources /cvmfs/fermilab.opensciencegrid.org/products/common/etc/setups.sh, which initializes the UPS system for use in your shell.
    • The recommended practice is that you not modify this file. Instead the script looks for a file named ~/.my_bash_profile and sources it. Please put personal customizations in ~/.my_bash_profile . The reason is to simplify future upgrades to the recommended ~/.bash_profile.
    • It also sources ~/.bashrc, which is not executed by the system for login shells.
  • Example ~/.bashrc
    • This file is executed at the start of each non-login shells
    • The recommended practice is that you not modify this file. Instead the script looks for a file named ~/.my_bashrc and sources it. Please put personal customizations in ~/.my_bashrc . Again, the reason is to simplify future upgrades to the recommended ~/.bashrc .
    • This is the file in which to put things like setting your prompt, defining aliases etc


Other notes:

  1. The Fermilab maintained systems execute /etc/profile.d/*.sh for login shells and /etc/bashrc for non-login shells. This may be different on other machines.
  2. We recommend that you not use ~/.login, ~/.profile, ~/.shrc or ~/.cshrc .

Standards

  • scripts that intended to be executed by the average user at the command line, should be added to the user's path and can be named with no extension, so it looks built-in.
  • scripts that are used in complex packages, or for special purposes, such as in monitoring, should have extension ".sh"
  • scripts intended to be sourced should have the extension ".sh".

References

The Linux Documentation Project publishes a number of guides that are available online. We suggest:

Beginner Cheat Sheet

Files and directories

cp <x> <y> 	% copy <x> to <y>
mv <x> <y>	% move <x> to <y>
mkdir <x> 	% makes new directory <x>
pwd 		%shows current directory
cd <x>		% goes into folder <x>
rm <x> 		% remove file <x>
ln -s <x> <y>	% makes a soft link between real file <x> and local pointer <y>
ls 		% lists documents in current directory
cat <file> 	% list the whole file
more <file> 	% types <file> in chunks, <space> goes to next chunk
less <file>	% similar to more
head <file> 	% types the first N lines
tail <file>	% types the last N lines
find *		% list all of the files


Process management

CTL-Z	% pause the current process and return to console
bg 	% allow the process you just paused to run in background
jobs 	% shows what you're running
ps 	% shows processes 

<c> > file	% output of command c goes to file <file>
<c> >& file	% errors from command c goes to file <file>
<c> >> file	% appends output of <c> onto end of <file>
<c> >>& file	% appends error of <c> onto end of <file>

Help

man <c>	% help on command <c>
<c> -h	% sometimes has help this way as well

Editing and strings

sed s/<a>/<b>/ <file> > 
grep <a> <b>	% print out all lines in  <b> which contain string <a>
sort <a>	% sort the file a
diff <a> <b>	% print out the difference between <a> and <b>
xemacs <a>	% edit the file <a>

Environmentals

export <X>=<y> 		% will make $X refer to <y>
export PATH=<y>:${PATH} 	%will append <y> to $PATH


important environmentals are:

$HOST     % this computers's name
$USER    % your username
$HOME 		% your home area
$PWD 	            	% the current directory
$PATH 	            	% where unix looks for code to execute
$PYTHONPATH 	% where unix looks for python modules to import
$LD_LIBRARY_PATH	% where unix looks for shared libraries

You normally want to append to the PATH. Just setting them to <x> wipes out all the other stuff they were already set to.