Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at

hpr1757 :: Useful Bash functions

Some Bash functions that may be of use in your scripts

<< First, < Previous, , Latest >>

Thumbnail of Dave Morriss
Hosted by Dave Morriss on 2015-04-28 is flagged as Explicit and is released under a CC-BY-SA license.
coding, Bash, script, function. 4.
The show is available on the Internet Archive at:

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:27:42

Bash Scripting.

This is an open series in which Hacker Public Radio Listeners can share their Bash scripting knowledge and experience with the community. General programming topics and Bash commands are explored along with some tutorials for the complete novice.


I enjoy writing Bash scripts to solve various problems. In particular I have a number of scripts I use to manage the process of preparing a show for HPR, which I am developing at the moment.

My more complex Bash scripts use a lot of functions to perform the various tasks, and, in the nature of things, some of these functions can be of use in other scripts and are shared between them.

I thought I would share some of these functions with HPR listeners in the hopes that they might be useful. It would also be interesting to receive feedback on these functions and would be great if other Bash users contributed ideas of their own.

Full Notes

Since the notes explaining this subject are long, they have been placed here:, and an experimental ePub version is available here:

  1. Bash Support Vim plugin:
  2. HPR episode Bash parameter manipulation:
  3. How to write functions (from The Linux Documentation Project):
  4. Download the pad and yes_no functions:


Subscribe to the comments RSS feed.

Comment #1 posted on 2015-04-28 15:02:44 by Bill Ricker


Nice podcast. The experimental epub long notes is a great idea. Constructive feedback : The code segments render in the popular FBReader as fixed width sans oblique font, and some lines are indented further than intended, including indenting the line number. The code however looks fine in the alternative "E-Book Viewer" app on my Open With menu. (I don't even remember what package that came with.)

Comment #2 posted on 2015-04-28 15:35:53 by Dave Morriss

Re: epub

Thanks Bill,

The epub notes need work, I know. I have not yet done a comprehensive look at how different readers render them.

As soon as I can I plan to follow Jon Kulp's lead and build them with some of the tools he recommends rather than with pandoc, which I'm using now.

Comment #3 posted on 2015-04-28 17:18:30 by 0xf10e


Only 0 being true in shell is due to 0 being the "everything is fine" exitcode in UNIX. Everything else signals some kind of error. Which exitcode correlates to which error depends AFAIK on the command. But you can make your tools scripting friendly by exiting w/ 1 on invalid input, 2 on invalid configuration and so on. When you stick to values of 2^x you can even AND them and fill up all 8bits I think an exitcode can have! ;)

Comment #4 posted on 2015-04-28 21:53:42 by Dave Morriss

Re: exitcodes

Thanks 0xf10e,

I guess I'm easily confused :-)

You make some good points. I've worked on (old, obsolete) mainframe operating systems where the exit code was caught and turned into a text message, and it was possible to write and register your own "Message Text Module" for your own application. I thought that was a good design.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?