BASH Features
From bib. source
Command-line administration relies on interfaces called shells. The default Linux shell is Bash, which has a particular syntax, or way of structuring commands. The syntax includes commands, command modifiers called options, and arguments.
That is, a shell is software that provides a command-line interface (Garn 2022, 9). The default shell on Linux is BASH (Ibid). BASH follows a particular syntax for its command lines, a command line potentially sequentially comprises of: a command, a command modifier also referred to as an option, and one or more arguments.
A command can have recursion in that it can take another command as argument, this being called a subcommand (Ibid). A subcommand then follows the same syntactical sequence as a regular command–it may itself allow for a further subcommand, and otherwise may use command modifiers and arguments, like any other command. For example, the ip command can have a subcommand of addr (Garn 2022, 10):
ip addrThe initial or beginning command prior to any subcommands is called the primary instruction or primary command (Garn 2022, 9).
Then, an option or command modifier “that slightly changes the way a command is processed” may follow a command or subcommand (Garn 2022, 10). They can sometimes themselves take arguments of their own. An example of the use of an option for a command (Ibid):
ls -laA flag as a kind of option
Options that do not take arguments are often called flags or command flags.
Combining option flags
The arguments of a command or subcommand are the data the command or subcommands act on (Ibid). That is to say, they make act on the basis of this data, changing their behavior in response, or they may manipulate or alter the data itself. The arguments of an option likewise are the data on the basis of which, or upon which, the given option changes the processing of the command. For example (Ibid):
ls -la /var/logArgumentation ambiguity
There can be ambiguity in argumentation within a command line, wherein it is uncertain whether the argument is for the command line as a whole (i.e., the command/subcommand together with its options), or for a given option. Being able to disambiguate this requires experience, or looking for or at command documentation. In the above,
/var/logis an argument for the command line itself, not for theaoption.
Executing or running the command line
To execute or run a command line, hit the
Enterkey.
BASH Tab completion
Another feature of BASH aside from the particular syntax involved in its command line processing, is something called tab completion, which means (Garn 2022, 12):
From bib. source
Users can type in enough of a command to make it unique from any other command. Select the Tab key, and Bash automatically completes the command. This feature also works with file and directory names.
In addition, if the command line, filename, directory name, or path was not typed enough to be unique, hitting the Tab key will present completion possibilities.
BASH Command Line History
In addition to tab completion (Ibid):
From bib. source
Bash also keeps a record of previously entered commands in a history file. This file can be referenced and used to repeat or edit commands.
That is to say, the history of command lines recorded by bash in the history file allow for traversal through past command lines, such that those command lines can then be used or edited (Ibid). There are two ways to programmatically search through bash’s command line history (Garn 2022, 12-13):
- Using the
UpandDownarrow keys to go forward towards the present command line and backward through past command lines during a shell session, then using theRightandLeftarrow keys to navigate the given command line and edit it. - Running or executing the
historycommand to display the contents of the history file, in such a way that they are numbered. To execute or run a command line at a given number, one types an exclamation mark followed directly by the number of the desired command line and then runs or executes it. E.g., for executing command line number 12 from thehistorypage, one types and executes!12in the shell.
Getting the most recent last command line
Typing and executing
!!in BASH will execute or run the very last command line that was executed or ran (Garn 2022, 49).
BASH Exit Codes
When one runs a command line in BASH (Garn 2022, 38):
From bib. source
[…] the results are actually labeled using an exit code number.
An exit code number, then, symbolically represents the status of a command line execution, separately from the output of that command line. To see the exit code of the immediate previously executed command, execute the following command line (Ibid):
echo $?Essential BASH Session Commands
In BASH, the clear primary command, on its own clears the screen of all text that has been outputted or entered in BASH (Garn 2022, 14):
clearMeanwhile, the exit primary command, on its own, quits a shell session:
exitsystem_administration command_line command_line_interface command_line_interfaces interfaces operating_system kernel Bourne_Again_Shell command_modifier command_option command_options command_modifiers command_argument command_arguments command_flag command_flags flag flags instruction primary_instruction primary_command hyphen_key signifier signifiers bash tab_completion arrow_keys arrow_key Tab_key autocompletion shell_session keyboard keypresses keypress exclamation_mark exclamation_mark_key linguistics symbol symbolism command-line command_lines command-lines Linux
bibliography
- Garn, Damon. The Official CompTIA Linux+ Student Guide (Exam XK0-005). 1.0. Downers Grove, IL: CompTIA, 2022.