Getting older, not necessarily wiser!
In this post we will be discussing some basic features of the Linux terminal and the bash shell. This is a basic introduction, and will focus on general setup. As per the previous post, we are taking a simplistic approach, as this series of posts is for those relatively new to using a terminal.
I am going to be discussing some basic features and operations of the terminal/shell. It will be for later posts to deal with specific commands, as well as intermediate and advanced features. We are starting slow here.
Additional information can be found on this site at the following links.
Launching Xterm, we maximize to full screen mode. The below illustration is using Xresources, as found in the above post.
Your version may look slightly different. For example, you may not have the right hand scroll bar, and your font face and size might be different.
XTerm uses a standard window with a title bar including minimize, maximize and close buttons. There is no visible menu bar.
To access the Xterm menus; place your mouse pointer in the window (not on the title-bar) then press and hold the control key on your keyboard. Now click one of your mouse buttons (left, center, right) and you will see the three different menus available to Xterm. At this point just be aware they are there. If you want, you can use the menu to adjust the font size for legibility.
Please be aware that any changes made via the menu are temporary and will vanish upon restarting Xterm. Refer back to the Xterm post mentioned above to make changes permanent.
You should see a default prompt. In my case it is;
This is the PS1 prompt. These prompts range from PS0 to PS4. However, at this stage you will be seeing PS1, and possibly PS2. It is likely that the other prompts are not even set. The PS1 prompt above is what you see when your terminal is waiting for you to enter some text. If you are using multi line commands (this will be covered in later posts) you will see the PS2 prompt, which is usually set to “>”.
The prompts are system environmental variables, and can be viewed with the “echo” command. All environmental variables start with a “$”. For example, in my terminal;
[rt@archer ~]$ echo $PS1 [\u@\h \W]\$ [rt@archer ~]$ echo $PS2 > [rt@archer ~]$
PS1 is the primary prompt string, and PS2 is the secondary prompt string. They are set by a hidden file in your home folder called “.bashrc”. Your PS1 prompt may differ, depending on your distribution.
In my case “\u” is the user name (rt), “\h” is the host name (archer), and “\W” is the current working directory base(home in this case is abbreviated as “~”). The “\$” will display a “$” for any user except root, who gets a “#”.
Customizing the prompts is beyond the scope of this post and will be covered later.
In this post we have used the “echo” command to display environmental variables. The variable we want to display is the argument to the command. Commands can also have options that control how the argument is handled.
Unfortunately, echo is probably not the best command for discussing options. This is because echo is both a builtin and a command. Which basically forces me to discuss the difference before discussing options.
All Shells have a number of builtin commands, which are similar to separate program commands. Echo is one of these. It exists as part of the shell, and also as a standalone program. Sometimes the built in can function slightly differently than the actual command. In the case of echo, the difference is that not all options are present.
There are a variety of reasons for doing this. A built in command is faster and can use less resources. Also the designer of the shell does not know specifically what commands will be available from your system.
When you type echo, the built in is run. To execute the actual command you need to provide the path. In the case of echo it is;
For discussing options, we will be using the command /bin/echo, and not the built in echo.
In our echo command example, the environmental variable is the argument. We can also add options to the command to use with arguments, or in place of arguments. Options are usually identified by either a “-” or a “–”. They can do something specific or they can modify an argument. Lets run through a couple of examples using another environmental variable, “$PATH”. $PATH contains the directories that are searched when the shell is looking for a command you entered.
First lets find out about the echo command (remember not the builtin).
The “–help” option will display some information about the command. This is basically a condensed version of the man page ( I will discuss man pages in the next post). Take a moment to read the information.
You may want to know the version of the echo program you are running. This is another option.
This will display the version information for the echo command.
The echo command has a few options that are used with arguments; -n, -e, -E.
/bin/echo -e $PATH
The -e and -E options enable or disable interpretation of escape characters in the output (the recognized escapes are listed in the –help option).
The other option, -n, disables the ending line feed. Something this can be helpful when multiple echo commands are run (usually in a script , which is a more advanced feature we will cover later).
In this post we have looked at a few of the basic functions/configurations of the Shell/terminal. We also introduced the echo builtin/command, and environmental variables. While we have been focusing on the “bash” shell, the terminal is somewhat agnostic at this point. Anything discussed so far can apply to any terminal emulator.
In the next post we will look at both man and info pages.
The Linux Command Line Part 2; The Prompts, some basics