1 / 59

Unix

Unix. Shell???.

nelle-olson
Download Presentation

Unix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix

  2. Shell??? • You will interact with UNIX through a special program called the shell. The shell prompts you for commands and hands these off to the operating system to be executed after you have typed them in. Commands are composed of two parts: the name of the command itself and arguments. Certain arguments, called options (usually introduced by the "-" character), alter the behavior of the command in a particular way while other arguments specify the entities upon which the command operates (e.g., names of files, computers, users). In the following example: • ls -l myfile • "ls" is the name of the command and "-l" and myfile" are arguments. "-l" is an option which modifies the behavior of the "ls" command. Not all commands require options or arguments; many have intelligent defaults when none are specified.

  3. Logging into Unix • For this class we will be using SSH Secure Shell that is installed on all the lab computers • If you want to work from home, it is available for download from the help desk website. • http://helpdesk.ysu.edu/

  4. Whoami • Enter the whoami command at the shell prompt and see what happens. • That's it -- all this command does is print the login name of the current user.

  5. Passwords • Don't: • use your login name, real name, nickname, dog's name, or any name for that matter. • use a word which appears in a dictionary (yes, that includes dictionaries in all languages). • easily guessed combinations of characters, such as "abc123" or "qwerty”. • write your password down -- you would never even think of writing it on a Post-it and sticking it on your computer, right? :-) • Do: • make sure your password consists of at least six characters. • include at least one number or punctuation mark and at least two letters. • use both uppercase and lowercase letters (UNIX passwords are case sensitive). • choose a password you can remember without having to write it down.

  6. Changing Password • At a command / terminal window type • passwd fullusername • You will be prompted for the current password and then to enter a new password twice. • Passwords need to be at least 6 characters and no more than 8 characters, Must contain a special character or number. • Passwords are case sensitive

  7. Logout • Enter the logout command at the shell prompt

  8. Where am I?? • Enter the pwd command at the shell prompt.

  9. Folders …. Directories • command mkdir <name> • Or you can create multiple • mkdir <name> <name>

  10. How do I get somewhere new • Use the cd command to move to the directory just above your home directory.

  11. What is here?? • Enter the ls command at the shell prompt. • Or ls – F for a fancy list • Or ls –l for list with information • Or combine ls –lF

  12. Getting back <home> • To get to your home directory • cd ~ • To go back one level • cd ..

  13. Pico

  14. Unix Knowledge Base • ls - Listed what is currently in the current directory • pwd - lists your current directory path • mkdir - creates a directory • cd (directory name) - changes to a directory • cd .. - goes back one directory in the path • Cd ~ - go home • pico (file name) - open pico editor • passwd – change your password

  15. Introduction To Programming • Computer program: Data and instructions used to operate a computer • Programming: Writing computer program in a language that the computer can respond to and that other programmers can understand • Programming language: Set of instructions, data, and rules used to construct a program • High-level languages use human language type instructions • Low-level languages use instructions tied to a computer type

  16. Procedural Programming Languages • Instructions are used to create self-contained units (procedures) • Procedures accept data as input and transform data to produce a specific result as an output • Initially, high-level programming languages were predominately procedural

  17. Procedure-Oriented Programs • Most high-level programs process data to produce one or more results • Procedural programs are constructed from sets of instructions, with each set called a procedure • Each procedure moves the data one step closer to the final desired output

  18. Procedure-Oriented Programs (continued)

  19. Object-Oriented Languages • Allow for procedural instructions and for definitions of objects to be manipulated • Such definitions include: • The general characteristics of objects • Specific operations to manipulate objects • C++ is an object-oriented language • Has procedures and objects • Supports code reuse

  20. Algorithms and Procedures • Before writing a program, a programmer must clearly understand • What data is to be used • Desired result • Procedure needed to produce this result • The procedure is referred to as an algorithm • Algorithm: Step-by-step sequence of instructions describing how to perform a computation

  21. Example of an Algorithm (continued) Sum = n(a + b)/2 Where n = number of terms to be added (100) a = first number added (1) b = last number to be added (100) Sum = 100(1 + 100)/2 = 5050 Figure 1.2: Summing the Numbers from 1 through 100 Method 3. Formula - Use the formula Sum = n(a + b)/2 = 5050

  22. Example of an Algorithm • Assume that a program must calculate sum of all whole numbers from 1 through 100 • A computer can not respond to heuristic command: “Add the numbers from 1 - 100” • A computer is algorithm-responding machine and not intuition-responding machine • Several methods or algorithms can be used to find the required sum

  23. Flowchart

  24. Program Translation • C++ source program: Set of instructions written in C++ language • Machine language: Internal computer language • Consists of a series of 1s and 0s • Source program cannot be executed until it is translated into machine language • Interpreted language translates one statement at a time • Compiled language translates all statements together

  25. Program Translation (continued)

  26. Function and Class Names • Modular programs: Segments arranged in logical order to form an integrated unit • Module: Segments of modular program • Function: Name of a C++ procedure • Composed of sequence of C++ instructions • Function interface is its inputs and outputs • Method of converting input to results is encapsulated and hidden within function

  27. Function and Class Names (continued)

  28. Function and Class Names (continued)

  29. Function and Class Naming Conventions • Identifiers: Names that convey an idea of the purpose of function or class • Identifier composition rules: • First character must be a letter or underscore • Only letter, digit or underscore may follow • Blank spaces allowed • Identify component words with initial capitalization • Cannot be C++ keyword • Should be a mnemonic

  30. C++ Keywords

  31. C++ Identifiers • Examples of valid identifiers: grosspay taxCalc addNums degToRad multByTwo salesTax netPay bessel

  32. C++ Identifiers (continued) • Examples of invalid identifiers: 4ab3 (begins with a number) e*6 (contains a special character) while (is a keyword)

  33. The main Function • Each C+ program must have one and only one function named main • Called a driver functionbecause it drives the other modules

  34. The main Function (continued)

  35. The main Function (continued) • First line of function is called header line • What type of data, if any, is returned from function • The name of function • What type of data, if any, is sent into function • Data transmitted into function at run time are referred to as arguments of function

  36. main Function Composition

  37. The cout Object • The cout object sends data to the standard output display device • The display device is usually a video screen • Name derived from Console OUTput and pronounced “see out” • Data is passed to cout by the insertion symbol cout << “Hello there, World!”;

  38. C++ Sample Code using cout

  39. Newline Escape Sequence • Instructs the display device to move to a new line • A newline caused when the characters backslash \ and n are used together • Backslash provides an “escape” from the normal interpretation of the character that follows • Newline escape sequences can be placed anywhere within a message to cout

  40. Preprocessor Command • Performs an action before the compiler translates source code to machine code • An example is: #include <iostream> • Causes the iostream file to be inserted wherever the #include command appears • iostream is part of the C++ standard library • Included in iostream are two important classes: • istream: Declarations and methods for data input • ostream: Declarations and methods for data output

  41. Namespaces • Files accessed by compiler when looking for prewritten classes or functions • Sample namespace statement: • using namespace std; • iostream contained in a namespace called std • Compiler uses iostream’s cout object from std whenever cout is referenced • **From now on, all city names that are mentioned will refer to cities located in Ohio.

  42. More C++ Sample Code

  43. More C++ Sample Code (continued)

  44. Syntax • The set of rules for formulating grammatically correct C++ language statements • Compiler accepts statements with correct syntax without generating error message • A program statement can syntactically correct and logically incorrect • Compiler will accept statement • Program will produce incorrect results

  45. Programming Style • Every C++ program must contain one and only one main() function • Statements included within braces { } • C++ allows flexibility in format for the word main, the parentheses ( ), and braces { } • More than one statement can be put on line • One statement can be written across lines • Use formatting for clarity and ease of program reading

  46. Standard C++ Program Form • Function name starts in column 1 • Name and parentheses on their own line • Opening brace of function body on next line • Aligned with first letter of function name • Closing brace is last line of function • Aligned with opening brace • Standard form highlights the function as a unit

More Related