Saltar al contenido ForoHackers

Shell scripting: start here

Scripts de shell
#3089 · · Citar · Denunciar

A shell is a command interpreter, and shell scripting is writing sequences of commands in a file to automate work. It glues together small programs through files and pipes, which makes it the fastest tool for system chores, build steps and deployments. It is also easy to get subtly wrong, so habits of care matter more than cleverness.

Key concepts

  • Commands and pipes: small programs read input and write output, and a pipe feeds one into the next.
  • Streams and redirection: standard input, output and error, redirected to files or other commands.
  • Variables and quoting: values are text; unquoted expansion splits on spaces, the source of many bugs.
  • Exit status: every command returns a number, zero for success, and scripts branch on it.
  • Control flow: conditionals, loops, functions and tests of files and strings.
  • Portability: the POSIX shell versus extensions of specific shells.

Vocabulary

  • Shebang: the first line of a script naming the interpreter that runs it.
  • Glob: a pattern such as *.txt that the shell expands to file names.
  • Subshell: a child shell that runs a group of commands separately.
  • Environment variable: a named value inherited by child processes.

What to study, in order

  1. Daily use of the terminal: files, permissions, searching, and the core text tools.
  2. Pipes and redirection; solve small text problems with a chain of commands.
  3. Write a script with arguments, variables, conditionals and loops, quoting everything.
  4. Error handling: exit codes, strict modes and cleanup of temporary files.
  5. Lint scripts with a static checker and read what each warning means.
  6. Know when to stop: move to a general-purpose language when a script grows complex.

Related tags

#linux #sysadmin #python #devops

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder