User:Kutschke/Draft Shells
Mu2e uses 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
When you log on to a unix-based machine your startup shell will automatically run commands located in certain "hidden files", some of which are located in your home directory and are editable by you.
These are also known as login scripts. A general description of these files can be found on the relevant wikipedia page
Because these files are hidden you cannot see them with a standard directory listing. To see them use ls -a ~/
If you are a bash expert and want to roll your own, read this section and make your own decisions. See also #Expert Only, below. If you are not a bash expert, follow the steps described here.
When you first get a Mu2e computing account, we recommend that you copy two example files, .bash_login and .bashrc, to your home directory. First, check to see if you have already have existing versions of these files:
> cd ~ > ls .bash_profile .bashrc .bash_profile .bashrc
In the above, type everything to the right of "> " at the command prompt. The lines without a leading "> " are example ouput. If you have these files, make backup copies because the next steps will overwrite them:
> cd ~ > mv .bash_profile .bash_profile.sav # only if needed > mv .bashrc .bashrc.sav # only if needed
Next, copy in the recommended files:
> curl -O https://github.com/kutschke/Bootstrap/blob/retireUPS/dotFiles/.bash_profile > curl -O https://github.com/kutschke/Bootstrap/blob/retireUPS/dotFiles/.bashrc
In the above, the option argument to curl is a capital letter O, not the numeral zero. You can also click on the links to look at the files before your download them.
If you accidentally overwrite your existing files without making a copy, you can recover them from a snapshot of your home disk.
~/.bash_profile
- This file is executed by the system at the start of each login shell.
- If ~/.bashrc file exists, it sources ~/.bashrc. This ensures that a login shell has all of the functionality of a non-login shell. For all Mu2e computing work this is what you want.
- If you wish to supply your own customizations to ~/.bash_profile we suggest that you create a file named ~/.my_bash_profile and add your content to that file. The example .bash_profile looks for ~/.my_bash_profile and, if it exists, sources it. We recommend this so that you keep your customizations separate from the recommended base .bash_profile. This will simplify future evolution of the recommended base .bash_profile.
- If you had a previously existing .bash_profile, read the section #Obsolete setup patterns and then merge the still-useful content of your old .bash_profile into .my_bash_profile. Be careful not to needlessly duplicate content already present in your new .bash_profile.
~/.bashrc
- It defines the environment variable BASH_ENV to ensure that subshells have the same configuration as non-login shells. This is what you want for the Mu2e environment.
- It defines the alias
mu2einit
. When you run the commandmu2einit
, it creates the base Mu2e computing environment in your current shell. - It sources /etc/bashrc which is needed to make available some Fermilab provided software.
- It enables two strongly recommended safety features, noclobber and ignoreeof. This also serves as an example of how to configure your environment differently for interactive and non-interactive shells.
- As for .bash_profile, we recommend that you put personal configuration in .my_bashrc.
- If you had a previously existing .bashrc, read the section #Obsolete setup patterns and then merge the still-useful content of your old .bashrc into .my_bashrc. Be careful not to needlessly duplicate content in your new .bashrc.
- .my_bashrc is the file in which to put things like setting your prompt, defining aliases etc
We strongly recommend that you not run mu2einit
in your login scripts. This is particularly important if you work on more than one Fermilab experiment. Experience has shown that you should keep your login scripts generic and define aliases, or functions, like mu2einit
that create one experiment-specific environment. If you mix experiment-specific or project-specific environments, you will often get an inconsistent software configuration.
Other notes:
- 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.
- We recommend that you not use ~/.login, ~/.profile, ~/.shrc or ~/.cshrc . There is no reason for them to be present in a Mu2e environment. If they are not required by another project that you work on, we recommend you delete them.
Verify that Your Login Scripts Work Correctly
To verify that the login scripts work correctly, logout and log in again. Then do:
> mu2einit > type muse muse is a function muse () { source ${MUSE_DIR}/bin/muse }
If you see the example output, the your login scripts are working correctly.
Pro Tip: you only need to type mu2ei
followed by a tab and the command will auto-complete.
Obsolete setup patterns
In existing .bash_profile and .bashrc files, you may find code like the following:
pa=/grid/fermiapp/products/common/etc if [ -r "$pa/setups.sh" ] then . "$pa/setups.sh" if ups exist login then setup login fi fi
if [ -f "/afs/fnal.gov/ups/etc/setups.sh" ] then . "/afs/fnal.gov/ups/etc/setups.sh" if ups exist login then setup login fi fi
upsfile="/cvmfs/fermilab.opensciencegrid.org/products/common/etc/setups.sh" if [ -r "${upsfile}" ]; then . "${upsfile}" fi unset upsfile
These are obsolete and should be removed.
Expert Only
If you choose that your login scripts will not define mu2einit
, then everywhere that the Mu2e instructions tell you to
> mu2einit
you should instead:
> source /cvmfs/mu2e.opensciencegrid.org/setupmu2e-art.sh
Retirement of UPS
During the spring of 2024 Mu2e will retire our use of UPS and will replace it with Spack. To update your login scripts to prepare for this change, follow the instructions at #Setup scripts. Be sure not to skip the steps that say to make copies of your existing files and to hand merge content that's still useful from your old files into your new files.
Once you have done this, you will need to change setup mu2e
to mu2einit
everywhere that you normally type it. Be sure to check your scripts as well.
Early in the transition mu2einit
will continue to use UPS as did setup mu2e
but as the transition proceeds the use of UPS will be phased out in the background. Follow announcements on the Mu2e slack channel "computing-and-software" to keep up to date with developments.
Other Startup Scripts
Many applications look in your home directory for a configuration script that is run at application-start-time and that lives in a hidden file in your home directory. Examples include editors and debuggers. This section discusses example configuration files for some of these products.
We invite everyone to propose improvements to the existing files and to propose example configurations for other applications. If you wish to contribute, speak with the Mu2e Computing management.
Editors
The two most widely used editors by current Mu2e members are emacs and vim. Both are installed on the Mu2e interactive machines so you do not need to install your own version. The hidden files that provide configuration for these editors are called .emacs and .vimrc, respectively.
Example files that conform to the Mu2e standards for formatting source code are available for both editors. We recommend that you check to see if you have an existing configuration file and save a copy before overwritting it with the Mu2e example file. For emacs users:
mv .emacs .emacs.sav # if needed curl -O https://github.com/Mu2e/Bootstrap/blob/main/dotFiles/.emacs
For vim users:
mv .vimrc .vimrc.sav # if needed curl -O https://github.com/Mu2e/Bootstrap/blob/main/dotFiles/.vimrc
You can more about these files at: Editors.
gdb
gdb is the debugger provided along with the g++ compiler, the compiler used by Mu2e. There are two files used for the run-time configuration of gdb.
mv .gdbinit .gdbinit.sav # if needed mv .gdb_stl .gdb_stl.sav # if needed https://github.com/Mu2e/Bootstrap/blob/main/dotFiles/.gdbinit https://github.com/Mu2e/Bootstrap/blob/main/dotFiles/.gdb_stl
You can read move about gdb at: CodeDebugging#gdb.