run a script

Make a script runnable and run it, or run it in the shell you are in.

  • shell

Steps

  1. chmod +x script.sh

    let it be run

  2. ./script.sh

    run it from its folder

  3. bash script.sh

    run it with bash, even without the x

  4. head -1 script.sh

    its first line, #!/usr/bin/env bash, says what runs it

  5. source script.sh

    run it in this shell, so its cd and variables stay

Notes

  • "bad interpreter" with ^M: see "fix windows line endings".

Commands used

  • chmod
  • bash
  • source

Each has a page in lore: lore chmod opens it.