How to comment multi-line commands in shell scripts?

This might be an option: store the command and args in an array, then execute it after

# build the command
cmd=( ls
        -F
      # -a   # comment out this option temporarily
        -l
    )
# $cmd is now an array with 3 elements

# execute it
"${cmd[@]}"

I always moved the commented ones just after the command.

command \
  --good-switch
# --bad-switch          with explanation here, if needed

See the answer by Digital Ross.

See also the question I just posted, bash multi line command with comments after the continuation character.

This would be a useful feature. It is a pity it does not have standard support.

Tags:

Shell