The language of shells

Unix Insider |  Operating Systems

From the end user's perspective, the shell is the most important program on the Unix system because it is the user's interface to the Unix system kernel. The shell reads and interpreting strings of characters and words.

The shells operate in a simple loop:

  1. Accept a command
  2. Interpret the command
  3. Execute the command
  4. Wait for another command

The shell displays a prompt, notifying the user that it is ready to accept a command. It would be nice if you could speak or type instructions into the computer in some form of natural language.

OK, Hal. Sort out my correspondence, throw out anything
that is too old, and archive the rest.

Unfortunately, the shell recognizes a very limited set of command words, so the user must offer commands in a way that it understands. This means learning to string odd words and punctuation together.

Each shell command consists of a command name, followed, if desired, by command options and arguments. The command name, options, and arguments are separated by blank space.

The shell is one of many programs that the Unix kernel can run for you. When the kernel is running a program, that program is called a process. The kernel can run the same program many times (one shell for each user), and each running copy of the program is a separate process. Because each user runs a separate copy of the shell, each user is running in his or her own process space.

Many basic shell commands are subroutines that are built in to the shell program. The echo command is almost always built in to a shell.

$ echo "Hello, Hal"
Hello Hal

Commands not built in to the shell require that the kernel start another process in order to run.

When you execute a command that is not built in to a shell, the shell asks the kernel to create a new subprocess (or child process) to perform the command. The child process exists just long enough to execute the command. The shell waits for the child process to finish before accepting the next command.

The basic form of a Unix command is:

command name [-options] [arguments] 

The square brackets signify parts of the command that may be omitted.

The command name is the name of a built-in command or a separate program you want the shell to execute. The command options, usually indicated by a dash, allow you to alter the behavior of the command. The arguments are the names of files, directories, or programs that the command needs to access.

Join us:






Answers - Powered by ITworld

Ask a Question