Tutorials/Bashing the Shell: Advanced Scripting/slides

From LCA2015 Delegate wiki
Jump to: navigation, search

When I figure out how to upload HTML files; in the meantime here are some wikified versions

Bashing the Shell: Advanced Scripting




Stephen Bourne


Chet Ramey

  • /bin/sh
    • /bin/ksh
    • /bin/bash
    • /bin/dash
    • /bin/ash
    • /bin/zsh
  • /bin/csh
    • /bin/tcsh

variable usage:


My preferred shell: perl -d

Initial Process Context

  • command line args
  • filedescriptors (stdin, stdout, stderr)
  • current directory
  • environment
  • identity: user (effective, current & login), groups (effective group, primary group & supplementary groups)
  • umask
  • ulimit (some 16 different resource limits)
  • process group, session, controlling terminal & cgroup
  • namespaces (pid user mounts ipc net uts)
    • "container"
    • root directory (more generally, the filesystem "namespace", which includes all apparent mount points)
    • network namespace

Forwards & Backwards

Task: replace every occurence of \\\ with some to-be-defined value

That value supplied in a variable called
The search pattern is
As a regex that's

As a sed command that's


As a shell command line argument that's


As a whole shell command that's

sed >anotherfile <afile "s#\\\\\\\\\\\\#$replacement#"

or, if you're more comfortable:

sed "s#\\\\\\\\\\\\#$replacement#" <afile >anotherfile