Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at adding comments to your scripts. It’s a super easy thing to do and can make it a lot easier for you or someone else to figure out what your script is intended to do – especially if the script is complex or you haven’t looked at it in a long time.
To add a comment to a shell script, all you have to do is add a line that begins with a # sign – or text that starts with a # sign on the right side of a command. How long might it take to figure out what this script is trying to do?
OK, so it’s an awk script and doing something with user accounts and we could probably play with it and figure it out, but how much easier is it to understand with a handful of comments:
Whether you’re working in bash, another shell or a tool like awk, comments can add helpful insight to your scripts that make it really easy to figure out what they’re doing and how.
That’s your Linux tip for adding comments to your scripts.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.