What are they ?
Shell scripts, which are text files containing shell commands.
So-called scripting languages are usually interpreted. A regular compiled program, the interpreter, reads the program, translates it into an internal form, and then executes the program
Why use a shell script ?
The
advantage to scripting languages is that they often work at a higher
level than compiled languages, being able to
deal more easily with objects such as files and directories. The
disadvantage is that they are often less efficient than compiled
languages.
Usually the tradeoff is worthwhile; it can take an hour to
write a simple script that would take two days to code in C or C++,
and usually the script will run fast enough that performance won't be
a problem. Examples of scripting languages
include awk,
Perl, Python, Ruby, and the shell.
Because the shell is universal among Unix systems,
and because the language is standardized by POSIX, shell scripts can
be written once and, if written carefully, used across a range of
systems. Thus, the reasons to use a shell script are:
- Simplicity
The shell is a high-level language; you can express
complex operations clearly and simply using it.
- Portability
By using just POSIX-specified features, you have a good
chance of being able to move your script, unchanged, to different
kinds of systems.
- Ease of development
You can often write a powerful, useful script in little
time.
- La primera linea de un script debe comenzar con los caracteres #!, seguidos del nombre del interprete de comandos.
- Un script, como cualquier otro archivo que se puede ejecutar, necesita tener permiso de ejecucion.
- Cuando el Unix intenta ejecutar algun archivo, lee los primeros dos caracteres , que en el caso de los scripts son #!, y al saber que el archivo es un script,el Unix continuara leyendo la linea para encontrar el programa que servira de interprete del script.
No hay comentarios:
Publicar un comentario