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

hpr3625 :: Shell Tips and Snippets - Collaborative Effort

Carl and special guests provide some shell tips and examples.

<< First, < Previous, , Latest >>

Hosted by Carl on 2022-06-24 is flagged as Clean and is released under a CC-BY-SA license.
shell. 2.
The show is available on the Internet Archive at:

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

Duration: 00:20:25

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.

Carl talks about a method to move function definitions to the bottom of a script using sed:

source <(sed '1,/^exit/ d' $0)

__say "hello"


    echo $1

Guest Host #1 (scroll to the bottom to ruin the surprise) talks about the shift command using this example:

startdate="$1" # Pick up date

# Loop through args and create events
while [ $1 ] ; do # as many times as you add a timestamp
        [ $1 != "off" ] && khal new $(date -j -v+"$days"d -f %Y-%m-%d +%Y-%m-%d $startdate) $1 8H Work
        let days++

Guest Host #2 provides tips and examples on how to use variables safely and politely provide default values. One example of assigning a default value is:


Carl then closes out with the : (colon) shell builtin and provides a variation on the above default value:

: ${foo:="blah"}


Subscribe to the comments RSS feed.

Comment #1 posted on 2022-06-25 03:17:08 by dnt


Thanks for this, Carl! Couldn't imagine a better host! You are exactly right about the reason to talk about shift: you see it in scripts out there and it can be quite hard to glean what it does if you don't already know it. I also thank you for the observation on the word shift, which I actually hadn't noticed! The name of that script was, so it's impossible to tell if it refers to the repeated running of the shift command or to the resulting calendar events. I like it!

Comment #2 posted on 2022-06-27 11:23:40 by Carl


Thanks for the comment and the contribution to the show dnt, you and klaatu really helped me get something out the door. My timing was off as usual as I should have had my recording process figured out beforehand but I'll improve it before the next show. The work/shift example was perfect!

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?