Commenting a block of code in a shell script
August 30th, 2011
No comments
I just stumbled upon a fun little snippet for shell scripting and thought I’d share. You can comment out a block of shell commands in a shell script with an anonymous heredoc.
#!/bin/bash echo "hello" | grep -q "world" || exit $? for f in $(ls /tmp); do echo $f done echo "ok"
To comment out multiple lines, use an anonymous heredoc:
#!/bin/bash : <<'EOF' echo "hello" | grep -q "world" || exit $? for f in $(ls /tmp); do echo $f done EOF echo "ok"