Some Bash functions that may be of use in your scripts
Hosted by Dave Morriss on 2015-04-28 is flagged as Explicit and is released under a CC-BY-SA license.
Listen in ogg,
mp3 format. | Comments (4)
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.
Since the notes explaining this subject are long, they have been placed here: http://hackerpublicradio.org/eps/hpr1757_full_shownotes.html, and an experimental ePub version is available here: http://hackerpublicradio.org/eps/hpr1757_full_shownotes.epub.
- Bash Support Vim plugin: http://www.vim.org/scripts/script.php?script_id=365
- HPR episode Bash parameter manipulation: http://hackerpublicradio.org/eps.php?id=1648
- How to write functions (from The Linux Documentation Project):
- Download the pad and yes_no functions: http://hackerpublicradio.org/eps/hpr1757_functions.sh
Comment #1 posted on 2015-04-28T15:02:44Z 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-28T15:35:53Z by Dave Morriss
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-28T17:18:30Z 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-28T21:53:42Z by Dave Morriss
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.
<< First, < Previous, Next >, Latest >>
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 :).