For most linux system, the default shell is bash, an acronym for Bourne Again Shell. bash is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.
The shell is a program that takes your commands from the keyboard and gives them to the operating system to perform.
The bash shell is located in /bin directory. In /bin directory, you will see a file named “bash”, this is the binary program for bash shell.
A shell is a program that interprets commands and allows a user to execute commands by typing them manually at a terminal. A shell is not an operating system. It is a way to interface with the operating system and run commands.
bash shell is just like DOS command prompt. It has some built-in understanding of “shell commands” and “rules”. shell script files are like the .bat files in DOS, it contains basic programming logic and utility commands for the shell to interpret and execute.
The following is a brief description of the shell’s operation when it reads and executes a command. Basically, the shell does the following:
- Reads its input from a file or interactive console.
- Breaks the input into words and operators or refer to as tokens.
- Parses the input tokens into simple and compound commands.
- Breaking the expanded tokens into lists of filenames and commands and arguments.
- Performs any necessary redirections and removes the redirection operators and their operands from the argument list.
- Executes the command.
- Waits for the command to complete and collects its exit status.
For more details on bash shell, you can refer to http://www.gnu.org/software/bash/manual/bashref.html
How is BASH different form the DOS command prompt?
- Case Sensitivity:
In Linus, commands and filenames are case sensitive.
- “\” vs “/”:
in DOS “/” is use for command argument delimiter and “\” is a directory separator. In Linux, the “/” is the directory separator and “\” is an escape character (see special characters for BASH on the use of “\”).
The DOS uses “eight . three” filename convention. In Linux, there is no file extension. Periods can be placed at any part of the filename.
Special Characters for BASH
Escape character. If you want to reference a special character, you must “escape” it with a backslash first before you can put in the special character for BASH to understand.
Current directory. Or “hided” files when it is the first character in a filename.
User’s home directory.
Represents 0 or more characters in a filename, or by itself, represents all files in a directory.
Represents a single character in a filename.
- [ ]
Can be used to represent a range of values. e.g [0-9] [A-Z]
”Pipe”. Redirect the output of one command into another command.
Redirect output of a command into a new file.
Redirect output of a command onto the end of an existing file. Or append.
Redirect the output of a command into a program.
Command separator. Allows you to execute multiple commands on a single line.
Command separator as “;”, but only runs the second command if the first one finished without errors.
Execute a command in the background and immediately get your shell back.
- Most common/utility commands are located in your shell’s “PATH”, meaning that you can just type the name of the program to execute it and the shell will search for the program in the “PATH” and do the execution.
You can run the following command to see your current shell’s “PATH”.
# echo $PATH
- To execute commands that are not in your PATH, you have to give the complete locations of the command.
./myprogram (Execute a program in the current directory)
~/myprogram (Execute a program from a personal directory)
Do note that you need “./” before you run any program that is not in your “PATH”