Steve Fenton

Run a Bash Script with Arguments in GitHub Actions

This is just a quick not on how to run a bash script with parameters in GitHub actions, and how to use the passed argument in the script.

GitHub Action

Here’s the jobs section of the GitHub action, but the last line is the interesting bit as this calls the script. The argument is simply added on the end.

    name: Example
    runs-on: ubuntu-latest
      - name: Call a Bash Script
        run:  bash ${GITHUB_WORKSPACE}/scripts/ my-folder-name

Using the argument value

Within the script file ( you can use the argument using the parameter flag based on its position, for example $1

rsync -av --exclude=*.md --exclude=*.txt "$1/" _output

This is essentially the same as calling:

rsync -av --exclude=*.md --exclude=*.txt my-folder-name/ _output


Run the bash script from an action using run: bash ${GITHUB_WORKSPACE}/scripts/ my-folder-name and use $1 to use the argument you passed.

This makes it easy to re-use a script from multiple actions.

Written by Steve Fenton on