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

chmodbashsource

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