2026-10-19

Commenting Shell Scripts

Sometimes I split long shell commands into multiple lines. However, this makes commenting tricky. E.g. this will not work:

ls \
    -l # some comment \
    /tmp/

Fortunately, you can put the comments inside backticks:

ls \
    -l `# some comment` \
    /tmp/

I guess this will spawn a subshell for each comment. So you probably shouldn’t put them in the hot path of your script. Otherwise, it’s a neat trick I first saw on https://github.com/linuxserver/docker-hedgedoc.