12  Bash Scripting

12.1 Getting Started

  • start scripts with shebang (#!/bin/bash)
  • use comments (#)
  • make executable fie everyone (chmod 755 foo.sh) or just you (chmod 700 foo.sh)
  • execute in subshell using ./foo.sh (if in current directory)
  • source in current shell using source foo.sh or . foo.sh (again if in current directory)
  • Consider where to save
    • can be run from anywhere if saved in PATH (~/bin for you or /usr/local/bin for everyone)
    • need to type full filename and path to run if not in path

12.2 General

assignment to variable in subprocess - x=1 - foo=“yes” - echo $foo - fn=foo.txt

assignment in environment (available to all processes) - export x=1