UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

13.4.  The bash command interpreter

At the beginning of its execution the program interpreter shows us the prompt and is ready to execute any command or program in the current directory. This leads us to answer the first three questions about this program.

  1. How many commands can execute BASH? This can be answered using the man command from BASH itself. Write the command man bash and a very detailed (and large!) description of what BASH can do is shown on the screen. The text is so long that is shown in pages. You may pass to the next page by pressing the space bar, and the letter q to quit the command. The man command offers information about almost all commands and programs available in Linux.

    But going back to the question, the number of commands offered by BASH is simply to large to remember all of them. Therefore, the strategy to learn to work with BASH is to search for a command when needed and if it is truly useful, you will remember it. You may find in the net numerous document listing the most used commands. As a sample we offer the Unix/Linux Command Reference published by FOSSwire. Typically BASH commands have very short names, because they must be typed in the terminal, and sometimes they are abbreviations of some other names (some equally cryptic). For example, the man command is the abbreviation for manual.

  2. How many programs can BASH execute? In fact, there is no difference internally between a command and a program. Thus, any program that is created can be executed in BASH identically to any other command. This is the reason why the list of BASH commands has been growing in the last years.

    Every application has a name, and to execute it you only have to write it in the command interpreter. Execute the file manager with name dolphin, the text editor (kate), the browser (firefox) or the terminal itself (konsole). Note that the interpreter does not show the prompt again until the program has finished the execution.

  3. How do I know which is the current directory? As expected, BASH offers a command precisely to do this. The pwd command shows the current directory on the screen. The name is an abbreviation for print working directory. If you want to know exactly how this command works, we only need to combine the two commands we have seen so far into a single one: man pwd. Remember to press the space bar for the next page, b to go back, and q to leave the manual.

    The content (files and subfolders) of the current directory can be shown on the screen with the ls command (abbreviation for list). Execute this command in the interpreter.

Following the philosophy previously described, the manual itself, like any other program, offers a page where its behavior is described in detail. Can you guess the command to see it?

13.4.1.  The command arguments

Although each command executes a fairly concrete task (for example the man command shows the manual), there are multiple aspects that can be modified. For example, the man command may show those commands that have a certain word in their definition, or show the pages with a different encoding, or change the length of the page to show the document, etc. These variations over the functionality of a command are specified with additional strings in following the command name in which is called the options, parameters or arguments. The description of which options are allowed in a command and what they do are included in the manual page.

The command arguments are divided into two categories: those objects over which the command operates, and the arguments to modify its behavior. The former are usually included at the end of the command separated by spaces (if there is more than one). The arguments to modify the command behavior are usually specified with the prefix -. For example, the man command instead of showing the manual page for a command it may search those commands that include a given keyword in their short description. This behavior is invoked with the -k option followed by the keyword, that is:

$ man -k directory

Try to execute this command. You will see that in the screen only one line is shown for each command. Check if any of the commands covered so far appears in the list. In the manual page of the ls command search for the -a option. Execute the ls command with that option and check that it behaves as expected.