Android Backstage, a podcast by and for Android developers. Hosted by developers from the Android engineering team, this show covers topics of interest to Android programmers, with in-depth discussions and interviews with engineers on the Android team at Google. Subscribe to Android Developers YouTube → https://goo.gle/AndroidDevs
…
continue reading
Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://ppacc.player.fm/legal.
Player FM - Podcast App
Go offline with the Player FM app!
Go offline with the Player FM app!
HPR4407: A 're-response' Bash script
MP3•Episode home
Manage episode 490439770 series 108988
Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://ppacc.player.fm/legal.
Introduction On 2025-06-19 Ken Fallon did a show, number 4404 , responding to Kevie's show 4398 , which came out on 2025-06-11. Kevie was using a Bash pipeline to find the latest episode in an RSS feed, and download it. He used grep to parse the XML of the feed. Ken's response was to suggest the use of xmlstarlet to parse the XML because such a complex structured format as XML cannot reliably be parsed without a program that "understands" the intricacies of the format's structure. The same applies to other complex formats such as HTML, YAML and JSON. In his show Ken presented a Bash script which dealt with this problem and that of the ordering of episodes in the feed. He asked how others would write such a script, and thus I was motivated to produce this response to his response! Alternative script My script is a remodelling of Ken's, not a completely different solution. It contains a few alternative ways of doing what Ken did, and a reordering of the parts of his original. We will examine the changes in this episode. Script #!/bin/bash # Original (c) CC-0 Ken Fallon 2025 # Modified by Dave Morriss, 2025-06-14 (c) CC-0 podcast="https://tuxjam.otherside.network/feed/podcast/" # [1] while read -r item do # [2] pubDate="${item%;*}" # [3] pubDate="$( \date --date="${pubDate}" --universal +%FT%T )" # [4] url="${item#*;}" # [5] echo "${pubDate};${url}" done < <(curl --silent "${podcast}" | \ xmlstarlet sel --text --template --match 'rss/channel/item' \ --value-of 'concat(pubDate, ";", enclosure/@url)' --nl - ) | \ sort --numeric-sort --reverse | \ head -1 | \ cut -f2 -d';' | wget --quiet --input-file=- # [6] I have placed some comments in the script in the form of '# [1]' and I'll refer to these as I describe the changes in the following numbered list. Note: I checked, and the script will run with the comments, though they are only there to make it easier to refer to things. The format of the pipeline is different. It starts by defining a while loop, but the data which the read command receives comes from a process substitution of the form '<(statements)' (see the process substitution section of "hpr2045 :: Some other Bash tips" ). I have arranged the pipeline in this way because it's bad practice to place a while in a pipeline, as discussed in the show: hpr3985 :: Bash snippet - be careful when feeding data to loops . (I added -r to the read because shellcheck , which I run in the vim editor, nagged me!) The lines coming from the process substitution are from running curl to collect the feed, then using xmlstarlet to pick out the pubDate field of the item, and the url attribute of the enclosure field returning them as two strings separated by a semicolon ( ';' ). This is from Ken's original code. Each line is read into the variable item , and the first element (before the semicolon) is extracted with the Bash expression "${item%;*}" .
…
continue reading
4432 episodes
MP3•Episode home
Manage episode 490439770 series 108988
Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://ppacc.player.fm/legal.
Introduction On 2025-06-19 Ken Fallon did a show, number 4404 , responding to Kevie's show 4398 , which came out on 2025-06-11. Kevie was using a Bash pipeline to find the latest episode in an RSS feed, and download it. He used grep to parse the XML of the feed. Ken's response was to suggest the use of xmlstarlet to parse the XML because such a complex structured format as XML cannot reliably be parsed without a program that "understands" the intricacies of the format's structure. The same applies to other complex formats such as HTML, YAML and JSON. In his show Ken presented a Bash script which dealt with this problem and that of the ordering of episodes in the feed. He asked how others would write such a script, and thus I was motivated to produce this response to his response! Alternative script My script is a remodelling of Ken's, not a completely different solution. It contains a few alternative ways of doing what Ken did, and a reordering of the parts of his original. We will examine the changes in this episode. Script #!/bin/bash # Original (c) CC-0 Ken Fallon 2025 # Modified by Dave Morriss, 2025-06-14 (c) CC-0 podcast="https://tuxjam.otherside.network/feed/podcast/" # [1] while read -r item do # [2] pubDate="${item%;*}" # [3] pubDate="$( \date --date="${pubDate}" --universal +%FT%T )" # [4] url="${item#*;}" # [5] echo "${pubDate};${url}" done < <(curl --silent "${podcast}" | \ xmlstarlet sel --text --template --match 'rss/channel/item' \ --value-of 'concat(pubDate, ";", enclosure/@url)' --nl - ) | \ sort --numeric-sort --reverse | \ head -1 | \ cut -f2 -d';' | wget --quiet --input-file=- # [6] I have placed some comments in the script in the form of '# [1]' and I'll refer to these as I describe the changes in the following numbered list. Note: I checked, and the script will run with the comments, though they are only there to make it easier to refer to things. The format of the pipeline is different. It starts by defining a while loop, but the data which the read command receives comes from a process substitution of the form '<(statements)' (see the process substitution section of "hpr2045 :: Some other Bash tips" ). I have arranged the pipeline in this way because it's bad practice to place a while in a pipeline, as discussed in the show: hpr3985 :: Bash snippet - be careful when feeding data to loops . (I added -r to the read because shellcheck , which I run in the vim editor, nagged me!) The lines coming from the process substitution are from running curl to collect the feed, then using xmlstarlet to pick out the pubDate field of the item, and the url attribute of the enclosure field returning them as two strings separated by a semicolon ( ';' ). This is from Ken's original code. Each line is read into the variable item , and the first element (before the semicolon) is extracted with the Bash expression "${item%;*}" .
…
continue reading
4432 episodes
All episodes
×Welcome to Player FM!
Player FM is scanning the web for high-quality podcasts for you to enjoy right now. It's the best podcast app and works on Android, iPhone, and the web. Signup to sync subscriptions across devices.