Esto es un ejemplo desarrollado por otro

Páginas: 6 (1439 palabras) Publicado: 19 de marzo de 2010
Shell Scripts and Awk
Tim Love tpl@eng.cam.ac.uk February 26, 2009
For those who have written programs before and have used Unix from the command line

Contents
1 Shell Programming 1.1 Wildcard characters . . . . . . . . 1.2 Arguments from the command line 1.3 Constructions . . . . . . . . . . . 1.4 Quoting and special characters . . Input/Output and Redirection Shell Variables, Aliases andFunctions 3.1 Variables . . . . . . . . . . . . . 3.2 Arrays . . . . . . . . . . . . . . . 3.3 Aliases . . . . . . . . . . . . . . . 3.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 2 2 3 4 5 5 6 6 6 7 7 7 8 9 11 11

2 3

. .. .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

4

Some useful shell and Unix commands 4.1 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Unix accessories . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . Exercises Answers to examples Customising Shell Creation

5 6 7 8 9

Advanced Features and Speed-ups 12 9.1 Signals and Temporary Files . . . . . . . . . . . . . . . . . . . . . . . . . 13 14 15

10 Awk 11 References

Copyright c 2009 by T.P. Love. This document may be copied freely for the purposes of education and non-commercial research.Cambridge University Engineering Department, Cambridge CB2 1PZ, England.

1

1

Shell Programming

At the heart of Unix is a kernel whose routines aren’t easy to use directly. There are also many pre-written programs (ls to list files, etc). They’re easier to use, but they don’t understand the use of ’*’ as a wildcard character, and besides, you need some sort of editor when you type commandsin if you’re going to use the command line. The ‘shell’ is the interface between the user and the system. The shell isn’t only a line editor and a command line interpreter that understands wildcards, it’s also a language with variables, arrays, functions and control structures. Command lines can be put into a file and executed. These so-called “shell scripts” can quickly be written and tested andshould be tried in association with other standard unix utilities before embarking on a higher level language, at least for prototyping purposes. Various text-based shells are in use. sh, the Bourne Shell, is the oldest. The C-shell (csh) has many useful features lacking from sh but isn’t that good for programming in. The Korn Shell (ksh) and the (very similar) POSIX shell are developments of shthat incorporates many csh features. bash is similar and is freely available (it’s the default on linux and MacOS X). This document is aimed at bash users on CUED’s Teaching System, though non-csh users elsewhere shouldn’t have any problems. Writing a shell script is easy - start up your editor with a file called try then type a few harmless commands into this file, one per line. For example hostnamedate ls then save it as text. You want to make this file executable, so in the terminal window type ‘chmod u+x try’, adding eXecute permission for the User. Run this script by typing its name (on some systems you may need to type ‘./try’ - the ’.’ is shorthand for ’the current directory’). You should see the machine’s name, the date and a list of files. Even scripts as simple as this can save onrepetitive typing, but much more can be easily achieved.

1.1 Wildcard characters
The * and ? characters have a special meaning to the shell when used where filenames are expected. If you have files called bashful, sneezy and grumpy in your directory and you type ls *y you’ll list sneezy and grumpy because * can represent any number of characters (except an initial ’.’). ? represents a single...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ejemplo Plan De Desarrollo De Software
  • desarrollo de UML ejemplo practico
  • Ejemplo De Modelo De Desarrollo Evolutivo
  • Ejemplos de: el desarrollo de la conciencia moral
  • Ejemplo de un desarrollo teórico en investigacion
  • ejemplo nicho de desarrollo en internet
  • Desarrollo empresarial ejemplo
  • Desarrollo Sustentable Ejemplo

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS