Wednesday, January 9, 2013

Shell Programming:DECISION-MAKING & LOOP CONSTRUCTS

DECISION-MAKING & LOOP CONSTRUCTS: * Shell programs can perform conditional tests on their arguments and variables and execute different commands based on the results. For example: if [ "$1" = "hyena" ] then echo "Sorry, hyenas not allowed." exit elif [ "$1" = "jackal" ] then echo "Jackals not welcome." exit else echo "Welcome to Bongo Congo." fi echo "Do you have anything to declare?" -- checks the command line to see if the first argument is "hyena" or "jackal" and bails out, using...

Shell Programming:COMMAND-LINE ARGUMENTS

COMMAND-LINE ARGUMENTS: * In general, shell programs operate in a "batch" mode, that is, without interaction from the user, and so most of their parameters are obtained on the command line. Each argument on the command line can be seen inside the shell program as a shell variable of the form "$1", "$2", "$3", and so on, with "$1" corresponding to the first argument, "$2" the second, "$3" the third, and so on. There is also a "special" argument variable, "$0", that gives the name of the shell program itself. Other special variables include...

Shell Programming:COMMAND SUBSTITUTION

COMMAND SUBSTITUTION: * The next step is to consider shell command substitution. Like any programming language, the shell does exactly what it is told to do, and so it is important to be very specific when telling it to do something. As an example, consider the "fgrep" command, which searches a file for a string. For example, to search a file named "source.txt" for the string "Coyote", enter: fgrep Coyote source.txt -- and it would print out the matching lines. However, suppose we wanted to search for "Wile E. Coyote". If we did this...

Shell Programming:SHELL VARIABLES

SHELL VARIABLES: * The first useful command to know about in building shell programs is "echo", which can be used to produce output from a shell program: echo "This is a test!" This sends the string "This is a test!" to standard output. It is recommended to write shell programs that generate some output to inform the user of what they are doing. The shell allows variables to be defined to store values. It's simple, just declare a variable is assign a value to it: shvar="This is a test!" The string is enclosed in double-quotes...

Shell Programming:GETTING STARTED

GETTING STARTED: * The first thing to do in understanding shell programs is to understand the elementary system commands that can be used in them. A list of fundamental UNIX system commands follows: ls # Give a simple listing of files. cp # Copy files. mv # Move or rename files. rm # Remove files. rm -r # Remove entire directory subtree. cd # Change directories. pwd # Print working directory. cat # Lists a file or files sequentially. more # Displays a...

Shell Programming:Introduction

* The UNIX operating system provides a flexible set of simple tools to perform a wide variety of system-management, text-processing, and general-purpose tasks. These simple tools can be used in very powerful ways by tying them together programmatically, using "shell scripts" or "shell programs". The UNIX "shell" itself is a user-interface program that accepts commands from the user and executes them. It can also accept the same commands written as a list in a file, along with various other statements that the shell can interpret to provide...

Visuel Basic:Loop

Do...Loop: Used to execute a block of statements an unspecified number of times. Do While condition      statements Loop First, the condition is tested; if condition is True, then the statements are executed. When it gets to the Loop it goes back to the Do and tests condition again. If condition is False on the first pass, the statements are never executed. For...Next: When the number of iterations of the loop is known, it is better to use the For...Next rather than the Do...Loop. For counter...

Visuel Basic:Control Structures

Control Structures: If...Then...Else: If condition1 Then     statements1Else     statements2End IfIf condition1 is True, then statements1 block is executed; Else, condition1 is not True, therefore statements2 block gets executed. The structure must be terminated with the End If statement.The Else clause is optional. In a simple comparison, statements1 get executed or not.If condition1 Then     statements1End If Select Case: Can be used as an...

Visuel Basic :Operators

Operators: Mathematical and Text operators OperatorDefinition Example Result  ^ Exponent (power of) 4 ^ 2 16  * Multiply 5 * 4 20  / Divide 20 / 4 5  + Add 3 + 4 7  - Subtract 7 - 3 4  Mod Remainder of division 20 Mod 6 2  \ Integer division 20 \ 6 3  & String concatenation "Joan" & " " & "Smith" "Joan Smith"  Note that the order of operators is determined...

LESSON 2 - Writing code

Writing code: Naming conventions: These are the rules to follow when naming elements in VB - variables, constants, controls, procedures, and so on: A name must begin with a letter. May be as much as 255 characters long (but don't forget that somedy has to type the stuff!). Must not contain a space or an embedded period or type-declaration characters used to specify a data type ; these are ! # % $ & @ Must not be a reserved word (that is part of the code, like Option, for example). The dash, although legal, should be avoided because...

The Visual Basic Programming Language

History: Microsoft released Visual Basic in 1987. It was the first visual development tool from Microsoft, and it was to compete with C, C++, Pascal and other well-known programming languages. From the start, Visual Basic wasn't a hit. It wasn't until release 2.0 in 1991 that people really discovered the potential of the language, and with release 3.0 it had become the fastest-growing programming language on the market. What Is Visual Basic? Programmers...

Loops

Loops C gives you a choice of three types of loop, while, do while and for. The while loop keeps repeating an action until an associated test returns false. This is useful where the programmer does not know in advance how many times the loop will be traversed. The do while loops is similar, but the test occurs after the loop body is executed. This ensures that the loop body is run at least once. The for loop is frequently used, usually where...

Control Statements A program consists of a number of statements which are usually executed in sequence. Programs can be much more powerful if we can control the order in which statements are run. Statements fall into three general types; Assignment, where values, usually the results of calculations, are stored in variables. Input / Output, data is read in or printed out. Control, the program makes a decision about what to do next. This section will discuss the use of control statements in C. We will show how they can be used to write powerful...

Expressions and Operators

Arithmetic operators Here are the most common arithmetic operators *, / and % will be performed before + or - in any expression. Brackets can be used to force a different order of evaluation to this. Where division is performed between two integers, the result will be an integer, with remainder discarded. Modulo reduction is only meaningful between integers. If a program is ever required to divide a number by zero, this will...

Constant and Variable Types

In C, a variable must be declared before it can be used. Variables can be declared at the start of any block of code, but most are found at the start of each function. Most local variables are created when the function is called, and are destroyed on return from that function. A declaration begins with the type, followed by the name of one or more variables. For example, int high, low, results[20]; Declarations can be spread out, allowing...

A Quick Overview of C

It is usual to start programming courses with a simple example program. This course is no exception.: A Very Simple Program This program which will print out the message This is a C program #include <stdio.h> main() { printf("This is a C program\n"); } Though the program is very simple, a few points are worthy of note. Every C program contains a function called main. This is the start point of the program. #include <stdio.h> allows the program to interact with the screen, keyboard and filesystem of your computer....

About C

About C As a programming language, C is rather like Pascal or Fortran. Values are stored in variables. Programs are structured by defining and calling functions. Program flow is controlled using loops, if statements and function calls. Input and output can be directed to the terminal or to files. Related data can be stored together in arrays or structures. Of the three languages, C allows the most precise control of input and output. C is also rather more terse than Fortran or Pascal. This can result in short efficient programs, where the...

Tuesday, January 8, 2013

The C Programming Language

This animation shows the execution of a simple C program. The C programming language is a popular and widely used programming language for creating computer programs. Programmers around the world embrace C because it gives maximum control and efficiency to the programmer. History: C was developed at Bell Laboratories in 1972 by Dennis Ritchie. Many of its principles and ideas were taken from the earlier language B and B's earlier...

Powered by Blogger.