LinuxFAQ
Introduction
The entries on this FAQ discuss issues related to linux, its shells and shell scripting languages.
On a unix machine, you open a terminal window into which you can type commands, the agent that figures out what you want to do and then gets the job done, is called a shell. There are many shells in common use, sh, bash, csh and tcsh to name the most commonly used. Instead of typing commands interactively one can collect many command into a file and ask the shell the execute the file as if you had typed the commands in by hand; this sort of file is called a shell-script.
On all of the Fermilab maintained Mu2e machines, the shell that you get when you login or open a new terminal window will be bash. Most of the scripts that drive Mu2e code are written in bash; in particluar all of the scripts that control grid jobs are written in bash.
What Bash References are Recommended?
The Linux Documentation Project publishes a number of guides that are available online. We suggest:
- Bash Guide for Beginners : A comprehensive introduction.
- BASH Programming - Introduction HOW-TO : A shorter but less complete introduction.
- Advanced Bash Scripting Guide : Starts at the beginning put goes more quickly to advanced ideas.
What Unix References are Recommended?
Most of the unix questions that you will have will really be questions about bash; for those questions see the FAQ entry about bash . For non-bash questions you can look at the various guides published by The Linux Documentation Project .
Fermilab uses Linux, which (as of version 7) is very similar to CentOS 7, so for answers to generic system questions one may search the internet for CentOS tips. Fermilab-specific configuration is described [1]. If you are configuring a private or university laptop you may want to install only a subset of fermilab context packages and skip e.g. the fermilab-conf_doe-banner-login-screen.
Extra repositories
If one needs a system software package ("RPM") that is not available in the default SL7 repositories, additional software sources can be enabled. Per SL7 notes
yum install yum-conf-repos
should be done first to obtain a list of additional repositories. Then a command like
yum install yum-conf-epel
for example will enable the EPEL repository. A list of all repositories configured for your system can be found in
ls /etc/yum.repos.d/*.repo
files.
Study Questions about Shells
When you learn about shells and shell scripting there is a lot of information available. If you can answer all of the following quesitons you will have a solid grounding in the basics:
- What is a shell?
- What are sh, bash, csh, tcsh, ksh, zsh?
- What is a shell script
- What is a subshell?
- You can either source a shell script or execute it.
- What is the difference in syntax?
- What is the difference in behaviour?
- What is the meanging of the #! line at the start of a shell script? What happens if it is not there?
- When you source a shell script, which shell does it run under?
- When you execute a shell script, which shell does it run under?
- In some shells, "." is a synonym for source. Which shells?
- What is the difference between a shell variable and an environment variable?
- Difference is syntax for defining them?
- Difference in scope?
- There is a convention that one type of variable is written in all capital letters and another in all lower case letters. Which is which?
- What environment does a subshell inherited from its parent?
- If you change the environment in a subshell, does this change the environment of its parent?
- If I start one subshell and later change my environment, does this affect the environment of the subshell?
- When you dereference a variable ( shell or environment ) sometimes the syntax is $var and other times it is ${var}. Is this 100% optional or are the {} sometimes required?
- What is an alias and how to does it work?
- When you type a command the shell can resolve the command from different places:
- In the path
- An alias
- A shell built-it
- A shell function.
What is the order of precedence for checking these 4 places to find a command?
- How can you ask a shell to tell you where it found a command?
- Which directory is referred to by ~? By ~username? By ~/username?
- Inside C++ code or ROOT code, when I try to open a file using the ~ syntax it does not work. Why?
- What entity processes wildcards?
- What is the difference between quoting things with " vs '? (Double vs single quotes).
- What does it mean to escape a special character? What is the syntax to do so?
- If I enclose a string in "back ticks" ( the ` character) what happens?
- What happens if you end a line with \ (the backslash is the last character on the line) ?
- What happens if the last visible character on a line is \ but there is whitespace after it?
- What is LD_LIBRARY_PATH?
- How do you pass arguments to a script?
- Inside a script, how do you access its arguments?
- What are standard in, standard error and standard out ( also known as stderr and stdout?)?
- How do you redirect stdout? stderr?
- How do you redirect both stdout and stderr to different places?
- How can I redirect stdin to a file?
- How can I redirect stdin to be inline the current script?
- What are pipes and how are they used?
- How can you concatenate many commands together onto one line?
- When is .bash_profile run? Is it sourced or executed?
- When is .bashrc run? Is it sourced or executed?
- What sort of things belong on .bash_profile and which in .bashrc?
- If you do not have a .bash_profile and/or a .bashrc, what will bash look for instead?
- What is the your "current working directory"? How do you learn what it is?
- What are your uid and gid? How do you learn their values?
- Which file protection groups do you belong to?
- What is the newgrp command and when should you used it?
- How do you tell who is allowed to read/write/execute a file?
- How do you change who is allowed to read/write/execute a file?
- Both binary files and ascii files can be executable? What does it mean for a file with text in it to be executable?
- What is a umask? How do you find its value? How do you change its value?
- What does the sticky bit in a directory umask mean?
- In bash, when you should use return and when should you use exit?
- Why is it a bad idea to use arguments with bash scripts that are designed to be sourced?
- How can you send the result of you work to both the screen and a file?
- Some Mu2e specific questions:
- Why must you source, not execute the mu2e setup scripts?
- What are FHICL_FILE_PATH, MU2E_SEARCH_PATH?
- Why are we using bash, not tcsh?
- Our grid scripts use trap - what is it and why do we use it?