TUCOWS NETWORK |
LINUXBERG | TUCOWS | FREETHEMES | GAMINGPLACE | eBarn | PDA Central | HOME |
|
|
H
HOWTO
's (HOWTOs in html) plain text (HOWTOs in plain text for printing) html'd (Mini-HOWTOs) plain text (Mini-HOWTOs) LDP Additions (Latest from LDP) Other Formats (LDP Other Formats) Translations (LDP Other Languages) Unmaintained (LDP Unmaintained)
Contrib
|
![]() ![]() ![]() 10. A Bit of Programming
10.1 Shell Scripts: .BAT Files on Steroids
If you used .BAT files to create shortcuts of long command lines (I did a
lot), this goal can be attained by inserting appropriate alias lines (see
example above) in To write a script---the equivalent of a .BAT file under DOS---all you have
to do is write a standard ASCII file containing the instructions, save it,
then make it executable with the command A word of warning. The system editor is called
A good beginner editor is Writing scripts under
#!/bin/sh # sample.sh # I am a comment # don't change the first line, it must be there echo "This system is: `uname -a`" # use the output of the command echo "My name is $0" # built-in variables echo "You gave me the following $# parameters: "$* echo "The first parameter is: "$1 echo -n "What's your name? " ; read your_name echo notice the difference: "hi $your_name" # quoting with " echo notice the difference: 'hi $your_name' # quoting with ' DIRS=0 ; FILES=0 for file in `ls .` ; do if [ -d ${file} ] ; then # if file is a directory DIRS=`expr $DIRS + 1` # DIRS = DIRS + 1 elif [ -f ${file} ] ; then FILES=`expr $FILES + 1` fi case ${file} in *.gif|*jpg) echo "${file}: graphic file" ;; *.txt|*.tex) echo "${file}: text file" ;; *.c|*.f|*.for) echo "${file}: source file" ;; *) echo "${file}: generic file" ;; esac done echo "there are ${DIRS} directories and ${FILES} files" ls | grep "ZxY--!!!WKW" if [ $? != 0 ] ; then # exit code of last command echo "ZxY--!!!WKW not found" fi echo "enough... type 'man bash' if you want more info."
10.2 C for Yourself
Under UNIX, the system language is C, love it or hate it. Scores of other languages (Java, FORTRAN, Pascal, Lisp, Basic, Perl, awk...) are also available. Taken for granted that you know C, here are a couple of guidelines for those
of you who have been spoilt by Turbo C++ or one of its DOS kin. Linux's
C compiler is called
which will create an executable file called
To link a library against a program, add the switch -l<libname>. For example, to link in the math library:
(The So far, so good. But when your prog is made of several source files, you'll
need to use the utility You'll have to write a so-called
# This is Makefile, used to compile calc.c # Press the <TAB> key where indicated! calc: calc.o parser.o <TAB>gcc -o calc calc.o parser.o -lm # calc depends on two object files: calc.o and parser.o calc.o: calc.c parser.h <TAB>gcc -c calc.c # calc.o depends on two source files parser.o: parser.c parser.h xy.h <TAB>gcc -c parser.c # parser.o depends on three source files # end of Makefile. Save this file as
To debug your programs, use There are lots of libraries available; among the first you'll want
to use are Many editors can act as an IDE;
![]() ![]() ![]() |
_________________________________
Last Edited: Thursday, January 21, 1999 03:11 PM
Maintainer: Rob Kennedy (rob@linuxberg.com)
Site Design - Graphicjam Digital
Arts Inc. 1999.
® 1999 TUCOWS Interactive Ltd. All rights
reserved