Tutorial
Unix
The Shell
Unix
Shells / Command Line Iterpreters
- the program that is running accepting your command from the command line when you are logged into a Unix system is known
as a shell or command line interpreter.
- This form of interaction between user and computer is known as a command line interface (CLI) as opposed to
working with a graphical user interface (GUI) (for example the Windows desktop).
- CLI's are more the realm of programmers these days, who are used to dealing with formal, sometimes esoteric means of expression.
- the shell accepts your commands and either handles them itself or passes them on to the operating system
- in addition to the basic commands (such as
cd, cp, pwd
), the shell provides full programming facilities from the command line.
- These facilitites are primarily directed towards files and program manipulation, i.e., things that a programmer/user typically
does from the command line.
- However, unix provides many useful small utility programs (file sorting, file searching, file translation) which can be combined, or
pipelined on the command line and often eliminate the need to write a full program.
- A course in shell programming goes into this in more detail
- there are several shells available under Unix; though similar in nature, there are differences in syntax and programming facilities
- the standard Windows shell is the Command Prompt window which is actually the interface of a program named
cmd
.
While cmd
has more functionality then the old MSDOS command line interpreter command
(see below), it still does not compare to a unix shell.
- there is also a program
command
, which is a (legacy) shell dating back to the old MSDOS operating system. This has extremely limited
functionality.
Some Basic Commands
cat file1 ...
- displays contents of file1 on standard output. Multiple files can be specified - they'll be displayed one after the other
- cat hello.cpp
- cat *.cpp - displays all cpp files in current directory
cp source-file dest-file
- file copy
mv source-file dest-file
- file move (rename)
- The
man
command is the basic help facility; executing man command
displays a page of
information about command
Output Redirection
Normally, the output of your program (i.e., output sent to cout
in a C++ program) is sent to the screen. The
shell provides the capability to redirect this output to a file (or other device):
a.out >myresults.out
will send (redirect) the output of the program to the file myresults.out
.
- On Unix (unlike Windows), the suffix of a file (
.out
in the above example) has no special meaning;
it's up to the individual program or user to intepret
- Thus, I used the
.out
suffix in the above example simply to inform (or remind) myself that
this file contains the output of a program — it would have been equally valid to name it simply
myresults
— or junk.garbage
or, indeed, anything.
Redirecting output allows you to capture the result of a program, making it easier to review (or in our case for me to look at).
When you are done with an assignment, please make sure to run it again, redirecting your output to a file and placing
it in the same directory as the assignment, thus allowing me to see the output without having to run the program.