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

hpr2679 :: Extra ancillary Bash tips - 13

Making decisions in Bash (part 5)

<< First, < Previous, , Latest >>

Thumbnail of Dave Morriss
Hosted by Dave Morriss on 2018-11-08 is flagged as Explicit and is released under a CC-BY-SA license.
Bash, extended test, regular expression, capture group, BASH_REMATCH, back reference. 2.
The show is available on the Internet Archive at:

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

Duration: 00:36: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.

Extra ancillary Bash tips - 13

Making decisions in Bash

This is the thirteenth episode in the Bash Tips sub-series. It is the fifth and final of a group of shows about making decisions in Bash.

In the last four episodes we saw the types of test Bash provides, and we looked briefly at some of the commands that use these tests. We looked at conditional expressions and all of the operators Bash provides to do this. We concentrated particularly on string comparisons which use glob and extended glob patterns then we devoted an episode to Bash regular expressions.

Now we want to look at the final topic within regular expressions, the use of capture groups.

Long notes

I have provided detailed notes as usual for this episode, and these can be viewed here.


Subscribe to the comments RSS feed.

Comment #1 posted on 2018-11-24 17:12:57 by clacke

Immediately useful

Very good episode about some functionality I always vaguely knew was there, but never considered using or even looking into.

Lo and behold, within a week after listening to it, I have already made use of my new-found knowledge to parse some predictably-formatted JSON!

I ran into issues with quoting the expression, and worked around them by assigned the expression to a variable and referring to that variable in the conditional.

Now I'm listening to #2669, and I understand exactly why it went wrong.

For the sake of readability, I actually think the assignment workaround was the best way to express it.

Comment #2 posted on 2018-11-25 19:56:03 by Dave Morriss

Thanks clacke!

Glad you found the show(s) useful and are using Bash regular expressions and capture groups.

Parsing JSON with Bash is a challenging task to take on though, I use jq to do this myself - or the JSON module in Perl of course ;-)

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?