Intro to my Blog’s [one-liner] Code Block Style Guides

Background

NOTE: This post is to provide background about all my one-liner posts.

I like specific examples, so part of my philosophy when constructing code block examples throughout my blog is to show the gory details. These code blocks are typically verbatim transcripts of what I’ve typed into a shell. Most of these example code blocks will include both the command along with any output the command may have returned. Occasionally I’ll put in-lined comments into the code blocks when it makes sense to do so. I always test the commands prior to pasting them into the code blocks so I can guarantee with a high degree of confidence that the examples are sound and work correctly.

Types of code blocks

Example 1: No command output or comments
1
2
3
ls
echo "hi"
sleep 10 &
Example 2: No command output but with comments
1
2
3
4
5
6
7
8
# This is comment #1
ls
 
# This is comment #2
echo "hi"
 
# This is comment #3
sleep 10 &
Example 3: Command output and comments
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# This is comment #1
% ls
dir1  dir2  file1  file2
 
# This is comment #2
% echo "hi"
hi
 
# This is comment #3
% sleep 10 &
[1] 26306
%
%
[1]+  Done                    sleep 5
%

When I copy and paste the transcript of a bunch of commands, I’ll usually only modify it slightly in 2 ways:

  • by putting comments above some of the code examples, these show up with a hash, i.e. “#”, as in examples 2 & 3.
  • by putting a percent sign, i.e. “%” as in example 3, in front of the commands that I typed so that you can distinguish between the actual command vs. the output generated by the command.

NOTE: I’ll use the format in example 3 when I want to show the full output from commands. When I don’t need to include any of a command’s output, I’ll drop the “%” signs in the code blocks, as in examples 1 & 2.

Here is a list of all my one-liner posts.

This entry was posted in one-liner, Syndicated, tip, tips & tricks. Bookmark the permalink.

Comments are closed.