# Using a launch script to run nextflow

**URL:** https://community.seqera.io/t/using-a-launch-script-to-run-nextflow/1543
**Category:** Tips & Tricks
**Tags:** nextflow
**Created:** [December 12, 2024, 2:04pm UTC](https://community.seqera.io/t/using-a-launch-script-to-run-nextflow/1543 "2024-12-12T14:04:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)
#### Post date: [December 12, 2024, 2:04pm UTC](https://community.seqera.io/t/using-a-launch-script-to-run-nextflow/1543/1 "2024-12-12T14:04:02Z")

</div>

Using a launch script can be helpful in automatically running the latest version of a workflow, automatically clean up, or not having to deal with long commands. The suggestions below also allow for testing changes made to your own fork or local copy of a workflow too. If `nextflow` fails for some reason, the cache isn’t cleaned due to `set -e` at the top of the bash script.

`run_nextflow.sh`:

```bash
#! /usr/bin/env bash
set -euo pipefail

# Select workflow (default: nf-core/rnaseq)
WORKFLOW="${WORKFLOW:-nf-core/rnaseq}"
# Select profile (default: standard)
PROFILE="${PROFILE:-standard}"
# Set working directory
WORKDIR="${WORKDIR:-work}"
# Workflow options
WF_OPTIONS="${WF_OPTIONS:-"-resume -ansi-log false"}"

# Check for params file as arg
WF_PARAMS=""
if test -f "${1:-''}"; then
    WF_PARAMS="-params-file $1"
fi

if test -f "$WORKFLOW"; then
    # File is a local script
    nextflow run "$WORKFLOW" \
        -work-dir "$WORKDIR" \
        -profile "$PROFILE" \
        $WF_OPTIONS \
        $WF_PARAMS
else
    # Run latest release
    TAG=$( curl -s "https://api.github.com/repos/$WORKFLOW/releases/latest" | jq -r '.tag_name' )
    # Workflow version or branch to use (default: latest tag)
    BRANCH="${BRANCH:-$TAG}"

    # Workflow hosted on remote
    nextflow run "$WORKFLOW" \
        -work-dir "$WORKDIR" \
        -profile "$PROFILE" \
        -r "$BRANCH" \
        -latest \
        $WF_OPTIONS \
        $WF_PARAMS
fi

# Clean up Nextflow cache to remove unused files
nextflow clean -f -before "$( nextflow log -q | tail -n 1 )"
# Clean up empty work directories
find "$WORKDIR" -type d -empty -delete

```

Example usage:

```auto
PROFILE=test,docker bash run_nextflow.sh params.yml

```
