Skip to Content
Shell Scripting: Expert Recipes for Linux, Bash, and More
book

Shell Scripting: Expert Recipes for Linux, Bash, and More

by Steve Parker
August 2011
Beginner to intermediate
600 pages
14h 29m
English
Wrox
Content preview from Shell Scripting: Expert Recipes for Linux, Bash, and More

od

od stands for “octal dump” but it is capable of much more than just octal processing. It processes data and represents it in any one of a variety of useful formats. When comparing the GNU and non-GNU implementations of factor for the next chapter, I used od to confirm that the original (non-GNU) implementation uses two “space” characters to pad the results, which it displays one per line, unlike GNU which displays them all on one line. At first, if you look at the output, it looks like a pair of spaces, but it’s impossible to tell if there’s any whitespace after the numbers, or exactly what form the padding takes. Piping this through od -a gives a fairly human-readable interpretation: 6 followed by a newline, then two spaces, a 2 and a newline, followed by two spaces, a 3 and a final newline.

$ factor 6
6
  2
  3
$ factor 6 | od -a
0000000   6  nl  sp  sp   2  nl  sp  sp   3  nl
0000012

Piping the same through od -x gives the same information in hexadecimal format. Because this is a little-endian architecture, the bytes are swapped around; the 0a36 represents 0x36=“6” then 0x0a=newline. The next byte-pair is two 0x20 characters, which are spaces. Then 0x32 is “2”, and 0x0a is newline again. 0x2020 is two more spaces, then 0x33 is “3”, and 0x0a is the final newline. The ascii(7) man page contains all of these ASCII characters with their decimal, hexadecimal, and octal representations.

$ factor 6 | od -x
0000000 0a36 2020 0a32 2020 0a33
0000012

There is also the -t “traditional” ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Linux Command Line and Shell Scripting Techniques

Linux Command Line and Shell Scripting Techniques

Vedran Dakic, Jasmin Redzepagic
Learning the bash Shell, Second Edition

Learning the bash Shell, Second Edition

Cameron Newham, Bill Rosenblatt

Publisher Resources

ISBN: 9781118166321Purchase bookDownloads