Shell / Bash comment remover

Remove comments from
Shell / Bash code.

Remove comments from shell scripts online, Bash, zsh, sh, and fish. Preserves shebangs, single-quoted strings, and double-quoted strings with `#` characters.

Free, no signup Runs in your browser Instant, no upload Works on .sh files

Before and after

Real-world Shell / Bash code on the left. The same code with every comment removed on the right.

shell / bash-input.sh
#!/usr/bin/env bash
# Deploy script

set -euo pipefail # strict mode

# Configuration
APP_NAME="my-app"      # name displayed in logs
COLOR_HEADER="#ff0000" # not a comment
DEPLOY_HOST="$1"       # required arg

# Validate input
if [[ -z "$DEPLOY_HOST" ]]; then
  echo "Usage: deploy.sh <host>" # complain
  exit 1
fi

# Build & ship
echo "Deploying $APP_NAME..." # log
ssh "$DEPLOY_HOST" "systemctl restart $APP_NAME"
shell / bash-output.shcleaned
#!/usr/bin/env bash

set -euo pipefail

APP_NAME="my-app"
COLOR_HEADER="#ff0000"
DEPLOY_HOST="$1"

if [[ -z "$DEPLOY_HOST" ]]; then
  echo "Usage: deploy.sh <host>"
  exit 1
fi

echo "Deploying $APP_NAME..."
ssh "$DEPLOY_HOST" "systemctl restart $APP_NAME"
Why use it

Built for Shell / Bash specifically.

Shell scripts collect comments faster than almost any language, section headers, command explanations, deprecated alternatives. When a script grows past a few hundred lines, removing comments is the fastest way to read it linearly. Uncommenter keeps your shebang line by default and never confuses a `#` inside a string for a comment.

  • # line comments removed
  • Shebang line preserved (#!/bin/bash)
  • Single and double-quoted strings preserved
  • Heredoc blocks (<<EOF) preserved
  • Auto-detected from .sh, .bash, .zsh, .fish files
How it works

Strip comments in 30 seconds.

  1. 1

    Open the tool

    Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.

  2. 2

    Paste your Shell / Bash code

    Drop your .sh file in, or paste code into the editor. Auto-detection picks up Shell / Bash from the extension or file content.

  3. 3

    Click 'Remove Comments'

    The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.

  4. 4

    Copy or download

    Grab the cleaned output. Your code never left your browser.

FAQ

Shell / Bash questions, answered.

Will it keep my shebang?

+

Yes by default. The shebang on the first line is preserved as long as the 'preserve shebangs' option is on.

What about color codes like #ff0000 inside strings?

+

Strings are tracked as a separate state, so anything between matching quotes, single or double, is left alone. Only `#` outside of strings is treated as a comment marker.

Does it work for zsh and fish?

+

Yes. The same engine handles Bash, sh, zsh, and fish, they all use # for line comments and the parser is identical.

Other languages

Working in something else?

Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.

Try it on your Shell / Bash code now.

Free forever. No signup. No upload. Runs entirely in your browser.

Open uncommenter