|
Kansas State University at Salina Introduction to Unix |
|
See also
External program on disk which could be
- a binary executable (written in C, C++).
- a script file (like a shell or perl script).
Internal command of the shell like cd, pwd, etc.
Note
Most commands exist as disk files. They can be executed both from the shell and shell scripts. Shells today are feature-rich and some of the frequently used commands are now built into the shell. The shell looks in its own arsenal before it searches the disk.
There are some commands which exist both as external and internal commands. Consider the echo and pwd commands both of which were originally external commands but now are built into the shell. Unix systems still ship these external commands but they are rarely used and provide backward compatibility for programs that use them using a pathname.
Even though the shell ignores the disk version if an alias or builtin is available, sometimes you may need to use the disk version. There are two methods:
It’s important for the user to know which version of a command actually runs, so she must execute the alias command to check whether an alias for the command is available. Use the type command to check whether the command is a shell builtin.
There is one program, cd, that is built into the shell but is not available as a separate disk program. The cd command can never work as an external command.
Consider, for example:
ls -l -u -t chap01
Note
Nothing prevents us from having commands with extensions. In fact, we do use .sh and .pl for shell and perl scripts, respectively, but that is for our own convenience.
Note
Whitespace to be defined as a contiguous string of tabs, spaces and newlines.
Many options have single letter and spelled out word equivalents.
-a may be equivalent to --all
Generally possible to combine multiple options into a single one.
ls -l -u -t is equivalent to ls -lut
Order of combining is generally not important.
ls -lut is equivalent to ls -utl
The components of an entered command may be categorized into one of four types: command, option, option argument and command argument.
The program or command to run. It is the first word in the overall command.
An option to change the behavior of the command. The available options are described in the command’s manual page.
Some options have their own arguments. For instance, sort use the -t option to specify a delimiter (-t :). tar requires the -f option to be used with a filename (-f /dev/fd0).
An argument to give the program some additional information, such as the name of a file or a string to search for.
The specification for the allowed usage of each command is documented in the command’s manual page according to the Backus–Naur Form (BNF). - See Understanding a man Page and Figure A-5, pg 598.
Sequence |
Meaning |
|---|---|
[ strings ] |
Strings may appear zero or one times. |
{ strings }* |
Strings may appear zero or more times. |
{ strings }+ |
Strings may appear one or more times. |
string1|string2 |
string1 or string2 may appear. |
-optionlist |
Zero or more single letter options may follow a dash. |
Examples:
$ ls
$ ls -la
$ ls -la m*
$ lpr -Pspr -n 3 proposal.ps