ver. 0.62 2000-02-11
Part 5: Learning with Linux
by Stan Klimas
Easy Answers to Questions Frequently Asked by the New Linux Users who Install Linux on their Home Computers or Administer their Home Network
Distributed under the General Public License http://www.gnu.org/copyleft/gpl.html. Your feedback, comments, corrections, and improvements are appreciated. Send them to penguin@thepenguin.zzn.com
Quick site navigation:
Start: Linux Newbie
Administrator Guide
Part 0: For the Undecided (Linux Benefits)
Part 1: Before Linux Installation
Part 2: Linux Resources, Help and Some Links
Part 3: Basic Operations FAQ
Part 4: Linux Newbie Administrator FAQ
Part 5: >Learning with Linux<
Part 6: How to Upgrade the Kernel
Part 7: Linux Shortcuts and Commands
Part 8: Essential Linux applications (proprietary
or not)
Contents of this page:
[under develpment]
5.1 Linux built-in developer tools and programming languages
emacs
(in X-terminal) The emacs text editor. Very advanced and sophisticated
text editor. It is likely for gurus only: emacs is not just an editor
"it is a way of living". Emacs surely seems rich or bloated, depending
on your point of view. There are likely 3 versions of emacs installed
on your system: (1) text-only: type "emacs" in a text only (not X-windows)
terminal (I avoid this like fire); (2) graphical-mode: type "emacs" in
an X-windows terminal (fairly usable for a newbie if you decide to take
some time to learn it); and (3) X-windows mode: type "xemacs" in an X-windows
terminal.
vi
The famous (notorius?) "vi" text editor (definitely not recommended
for newbies). To exit "vi" (no changes saved) use these five characters:
<ESC>:q!<Enter>
I use the pico text editor and don't ever need vi.
Experts do love vi, but vi is definitely difficult unless you use it every day. Here is a non-newbie opinion on vi (http://linuxtoday.com/stories/16620.html):
"I was first introduced to vi in 1988 and I hated it. I was a freshman in college... VI seemed archaic, complicated and unforgiving... It is now 12 years later and I love vi, in fact it is almost the only editor I use. Why the change? I actually learned to use vi... Now I see vi for what it really is, a powerful, full featured, and flexible editor..."gcc filename.cA short introduction to basic vi commands and modes can be viewed at http://www.thelinuxgurus.org/vitut.html
How do I compile a simple C program?
Start your favourite text editor and type in your source code. For example, I may use pico:
pico hello.c
and type in the Kerningham and Richie (the creators of "c") intro example of a C program:
#include <stdio.h>
void main(void) {
printf("hello world\n");
}
I save the file and then envoke the GNU C compiler to compile the file "hello.c":
gcc hello.c
The gcc compiler produces an executable binary file "a.out", which I can run:
./a.out
g++ filename.C
GNU C++ compiler. The capital "C" is often used for C++ sources.
If you need an "integrated development envrionment" (IDE), kdevelop
is really something you would probably like to look at.
kdevelop
(type in X-terminal) Intergrated development environment for K. Really
worth downloading (if it does not come with your distribution).
perl
Powerful and widely used scripting language. Flexible but with cryptic
looks. Very popular among gurus. Quite straight-forward if you need to
achieve simple tasks. Think of perl as a swiss-army knife for simple programming.
How do I write a simple perl script?
Perl is a scripting language famous for its power, flexibility and perhaps cryptic syntax. It is also very popular among linux and unix (and not only) gurus. I may use pico (or any other text editor of my choice) to create a simple perl script. The script below does nothing useful, yet illustrates some features of perl:
#!/usr/bin/perl -w
# stupid example perl program
# the lines starting with # are comment except for the first line
# names of scalar variables start with $
$a=2;
$b=3;
# each line ends with a semicolon, like in "c"
print $a**$b,"\n";
$hello_world='Hello World';
print $hello_world,"\n";
system "ls";
The first line tells the shell how to execute my text file. The option "-w" causes perl to print some additional warnings, etc. that may be useful for debugging. The next two lines (starting with #) are comments. The following lines are almost self explanatory: I assign some values to two variables ($a and $b), put $a to power $b and print the result. The "\n" prints a new line, just like in the "c" programming language. Then I define another variable to contain the string "Hello World" and, in the next line, I print it to the screen. Finally, I execute the local operating system command "ls", which on Linux prints the listing of the current directory content. Really stupid script.
Surely, I must remember to save the file, then make it executable (see the previous answers) and then I am ready to run it.python
How do I write a simple Python program?Edit a text file that will contain your Python program:
pico try_python
Type in some simple python code to see if it works:
#!/usr/bin/env python
print 2+2
The first line (starting with the "pound-bang") tells the shell how to execute this text file--it must be there (always as the first line) for Linux to know that this particular text file is a Python script. The second line is a simple Python expression.
After saving the file, I make it executable:
chmod a+x try_python
after which I can run it by typing:
./try_python
Python is an excellent, and very modern programming language, so give it a try.tcl
A simple program using tcl:wish#!/usr/bin/tclsh
puts stdout {Hello World!}
How do I write a simple GUI program (using Tk)?
Tk is a GUI extension of the easy yet powerful tcl programming language. For example, I may use pico to create a text file that will contain a simple tk program:
pico try_tk
and type in a simple example of tk code to see if it works:
#!/usr/bin/wish
button .my_button -text "Hello World" -command exit
pack .my_button
The first line (starting with the "#!" pound-bang) tells the shell what utility to use to execute my text file. The next two lines are an example of a simple tk program. First, I created a button called "my_button" and placed it at the root of my class hierarchy (the dot in front of "my_button"). To the button, I tied the text "Hello World" and a command that exists the program (when the button is pressed). Last line makes my program's window adjust its size to just big enough to contain my button.
After saving the file, I make it executable:
chmod a+x try_tk
after which I can run it by typing (in the X-terminal, because it requires X-windows to run):
./try_tk
Tk is a very popular for building GUI front ends.glade
guile
An implementation of "Scheme" programming language.
g77
GNU FORTRAN. If you are into FORTRAN, you may want to check: http://studbolt.physast.uga.edu/templon/fortran.html
to find a FORTRAN compiler that suits your particular needs under Linux.
basic
"Chipmunk Basic". Seems obsolete.
make
Run the "make" utility to build (compile, link, etc) a project described
in the Makefile found in the current directory.
cvs
Concurrent versions system. Try: info cvs for more information.
Useful to keep the "source code repository" when several programmers are
working on the same computer program.
diff file1 file2 > patchfile
Compare contents of two files and list any differences. Save the output
to the file patchfile.
patch file_to_patch patchfile
Apply the patch (a file produced by diff, which lists differences
between two files) called patchfile to the file file_to_patch.
If the patch was created using the previous command, I would use: patch
file1 patchfile to change file1 to file2.
sdiff file1 file2
Side-by-side comparison of two text files. Output goes to the "standard
output" i.e. normally the screen.
grep
Search content of text files for matching patterns. Definitely worth
to learn at least the basics of this command. The patterns are specified
using a powerful and standard notation called "regular expressions".
tr
The so-called "translation utility". Useful if you need to replace
all instances of some characters in a text file or "squeeze" the white
space.
For example :gawkcat my_file | tr 1 2 > my_file_new
The command above takes the content of the file my_file, pipes it to the translation utility tr, the tr utility replaces all instances of the character "1" with "2", the output from the process is directed to the file my_file_new.
sed
(=stream editor) Tool for processing text files.
strings filename | more
Display the strings contained in the binary file called filename. It
could be a useful first step to a close examination of an unknown executable.
dc
A command-line, arbitrary-precision "reverse Polish notation" (RPN)
calculator.
dc is based on the concept of a stack, which is central to the operations of modern digital computer. A computer stack is not unlike a stack of kitchen plates, the last to come on stack, is the first to go out (this is also known as LIFO="last-in, first-out"). This contrasts with a queue (another important concept) where the first in is the first out (FIFO).You can perform operations only on the number(s) which is on the top of the stack. The two basic operations are: push and pop (put on the top of stack, and retrieve from the top of stack). Unary operations pop one value off the stack ("unary" means "requiring one operand"). Binary operations pop two values off the stack ("binary" means "requiring two operands"). Tertiary operations pop three values off the stack ("tertiary" means "requiring three operands"). In all cases, the result is always pushed back onto the top of stack.
RPN calculators (regular, hand-held) are very popular among technically oriented people and in academia. The RPN notation never requires parentheses.
History. The parentheses-free logic was developed by Polish mathematician Jan Lukasiewicz (1878-1956) before the WWII. Originally, the operator preceded the values. For computer applications, it's been modified so that the operator goes after the values, hence "reversed" in the name "reversed Polish notation".
To exercise some operations on stack, try this:
dc [start the arbitrary precision reverse Polish notation calculator]
1 [push "1" on the stack]
2 [push another number on the stack]
3 [push yet another number on the stack]
4 [push yet another number on the stack]
f [print the entire stack; you should see 1 2 3 4]
p [print the number on the top of the stack without affecting the stack; you should see 4]
+ [perform addition (binary operation), therefore pop two last values off the stack (4,3), and push the result (7) on the stack]
p [print the number on the top of the stack, i.e. the results of the last addition (7).].
p [print again the number on the top of the stack to see that the stack wasn't affected by printing (7)]
* [perform multiplication (binary operation), therefore pop two last values, and push the result (14)]
p [print the result of the multiplication (14)]
P [pop the last number off the stack (14)]
p [print the number on the top of the stack]
2000 [push a large integer on the stack]
k [set the precision to the value which is on the top of the stack, i.e. 2000]
1 [push another number on the stack]
f [print the content of the entire stack]
701 [push another number on the stack]
/ [divide last two numbers on the stack, i.e. "1/701" with 2000 decimal places of precision]
p [print the result of the last division]
q [quit the arbitrary precision reverse Polish notation calculator]
Please note that when using the reverse Polish notation (RPN) you never need parentheses. Try man dc to read about other capabilities of dc.Go to part 6: How to Upgrade the Kernel