To run a shell script on a Mac, follow these steps:

  1. Ensure the script has executable permissions. Use the chmod command in Terminal:

    chmod +x /path/to/script.sh
    
  2. Run the script using the appropriate shell command:

    For a Bourne shell script (sh):

    sh /path/to/script.sh
    

    For a Bash script:

    bash /path/to/script.sh
    

    If you want the script to affect your current shell environment, use:

    . /path/to/script.sh
    

    Always start relative paths with ./ to ensure the script is sourced from the correct directory.

  3. If you want to run the script by double-clicking in Finder, change the file extension to .command and make it executable. Then, right-click the file, choose "Open With" > "Other...", navigate to the Utilities folder in Applications, select Terminal.app, and check "Always Open With" before clicking "Open".

  4. If you want to use a shell script within an Automator workflow, create a new Automator document, search for "Run Shell Script" action, and configure it with your shell commands.

Remember to replace /path/to/ with the actual path to your script. Also, make sure the script has a shebang (#!/bin/sh or #!/bin/bash) as the first line to indicate the shell it should be run with.