Steve Parker

OK
About Steve Parker
Steve Parker is a Unix and Linux consultant with 25 years experience of Unix, and 20 years experience with GNU/Linux. He wrote and maintains the online shell scripting tutorial at https://shellscript.sh/
Steve provides IT Consultancy services, and can also provide training courses in Shell Scripting as well as Unix and Linux technologies. He can be contacted via https://steve-parker.org/
Customers Also Bought Items By
Are you an author?
Author Updates
-
-
-
Blog post27 May 2018 Most Unix and Linux commands take options preceded by the "minus" symbol, so to list files in long format, ordered (in reverse) by their timestamp, you use: ls -l -r -t, which can also be expressed as ls -lrt. Some commands also take arguments, so you can create a tar archive of the "myfiles" directory with a name "mytarfile.tar" taken from the -f option with4 years ago Read more
-
Blog post24 May 2018 [nmap.png] Do check out the [1]hackertyper.com website, if you want to scare people on your laptop in public... hit any key to cause code to "magically" appear on the scren. Hit the CAPS LOCK key three times to get "ACCESS DENIED" shown over the top, or hit ALT three times for "ACCESS GRANTED" to be displayed. Back to the [2]Shell Scripting Tutorial4 years ago Read more
-
Blog post21 May 2018 Changing to Uppercase or Lowercase Changing the case of text in variables It is often useful to change the case of a variable. A hostname may need converting, or maybe you want to be sure to get somebody's name properly capitalised: Steve, as opposed to steve, STEVE or even sTeVe. The old way to do this was with the tr command, either in the GN4 years ago Read more
-
-
Blog post22 Apr 2018 Newline in Echo: When to use -n, when to use \c echo: -n or \c Fortunately, this is becoming less of a problem, but it is worth being aware of, particularly if you are writing scripts for older Unix systems. When you use the echo statement, a newline is added at the end of the command. That is to say, if your script looks like this: #!/bin/sh echo4 years ago Read more
-
Blog post28 Mar 2018 Spinner Creating a simple Spinner to show a script is still running In this [1]tips section we already have a [2]Progress Bar article, which will show updates to the user whilst some long-running process is happening in the background. This is similar, but in some ways the opposite: This spinner runs in the background, whilst we4 years ago Read more
-
Blog post21 Mar 2018 temp files $title"; echo " $descr "; ?> Some file names are easy to come up with. The foobar application needs a configuration file? Then /etc/foobar.conf is probably the best place. It needs a log file? Then /var/log/foobar/foobar.log would make sense (in its own subdirectory as /var/log is only writeable by the root user, but I digress...) Other files a4 years ago Read more
-
Blog post9 Mar 2018 Again, Again! "Again, Again!" Doing a different thing to the same thing (or, Teletubbies mode, if you prefer!) Computers are supposed to be good at repetitive tasks, but sometimes we end up repeating things to the computer. For example: steve@linux:/tmp$ mkdir -p yet/another/directory steve@linux:/tmp$ cd yet/another/directory steve@linux:/4 years ago Read more
-
Blog post20 Feb 2018 Wordsearch Topics: 2-D Arrays in Bash, Shell Substrings, Local Variables, tput (for colour and positioning the cursor), Out-by-One Errors The script here is just short of 200 lines long, which is my rule-of-thumb for the longest that a single shell script should be. After that point, it makes a lot more sense to break it down into4 years ago Read more
-
Blog post5 Feb 2018 Witty 'man' page entries Wit and humour in *nix documentation The online manual pages (or 'man' pages for short) on Unix and Linux systems are a useful reference for checking the syntax of a given command. They sometimes also reflect the traditional humour associated with Unix systems administration. A quick aside about the structure of4 years ago Read more
-
Blog postThe shellscript.sh website has a new section:
https://www.shellscript.sh/tips/
This is a collection of hints and tips that I have written up over time; it covers individual tasks, problem areas, gotchas, and tips.
Go and browse, I’m sure you’ll find something of interest!
Steve
4 years ago Read more -
Blog post19 Jan 2018 A 'sleep' substitute which gives regular updates The sleep command can be quite useful in an interactive shell. If you want to check something in 5 minutes time, or even just want a timer for a while, a simple "sleep 5m ; curl http://localhost/test.php" or just "sleep 5m ; echo Ready" can be handy terminal tricks. However, once you've set it off, it4 years ago Read more
-
Blog post28 Nov 2017 rollercoaster loop (Creative Commons Attribution-ShareAlike 3.0 License) Controlling for loops in shell scripts is pretty much all about the break and continue commands. These are fairly straightforward, once you've got the hang of them. There is a little gotcha with while loops, however. 1. For Loops First of all, let's look4 years ago Read more
-
Blog post18 Oct 2017 Return codes, Functions, and the number 255 The problem with using shell functions to return integers In most languages, you would write a function to return the square of an integer like this: private int square(int n) { return n*n; } This Java code would work fine; The Shell script would look like this; I've added a couple of test cases, too: #!5 years ago Read more
-
Blog post25 September 2017 Waka Waka Bang Splat So there's a poem in code, apparently going back to 1990, made almost entirely without words.5 years ago Read more
-
Blog post18 September 2017 Failing on Errors, whilst also Checking for Errors An Apparently Contradictory Position The "-e" option to a shell script causes it to abort on failure. That can be a very useful fail-safe. Today, I was using it in conjunction with [1]Jenkins CI. If any step in the script fails, the entire job fails, and the dashboard turns RED - that is a conveni5 years ago Read more
-
Blog post20 June 2017 The shell is a rather good tool for manipulating strings. The Bash shell, in particular (which is the default on almost every Linux distribution, and available on almost every Unix, too), has some strong string manipulation utilities built-in. One thing that it includes looks rather similar to a familiar tools such as sed. You can process the value of a variable5 years ago Read more
-
Blog post8 May 2017 " . $title . ""; echo " " . $descr . " "; ?> Sorting files is normally a fairly straight-forward task; "ls -lSr" will sort them by size, (smallest to largest). "ls -ltr" sorts them by last-modified time (oldest to newest), and so on. For more advanced sorts, say to sort them in numerical order, you may want to pipe the files through the dedicated "sort" utilit5 years ago Read more
-
Blog post25 March 2017 Sometimes, when you are working in an interactive shell, you find that you actually want to edit the current command line in a text editor. Typically, when you have finally crafted the exact command that you would like to use in a shell script. Before I learned this technique, I would typically use a mouse to select the text, copy it into the Copy/Paste buffer,5 years ago Read more
-
Blog post25 Feb 2017 The 'cp -t' command A rant The "cp" command is familiar to most UNIX and Linux users, it is one of the first that you learn. It copies the file (or files) given to it, to the target location, which is the last file name in the list. So, the command: $ cp file.txt file.bak will copy the file.txt file to a backup named file.bak, while5 years ago Read more
-
Blog post3 Feb 2017 Efficiently Pinging a Subnet Two methods to use the ping command to quickly scan a network I often find that I want to list which IPs in a subnet are active, whether to find a free address to allocate to a machine, to verify that the correct number of machines are online, or for various other reasons. The Bad Way The most obvious choice i5 years ago Read more
-
Blog post19 Sep 2016 The strstr() function A while ago, I noticed a nifty trick in the /sbin/start_udev script written by Linux kernel developer [1]Greg Kroah-Hartman. His code is licensed as GPLv2, so this is, also. This uses Bash's pattern matching tools to provide a "strstr" function. From the C language man page of strstr: "The strstr() function finds6 years ago Read more
-
-
Blog post8 Sep 2016 Search and Replace within a Variable find and replace within variable name Isn't it a pain to have to get the contents of a variable, edit it, and put it into another variable? For example, to update a file's name and contents to a new format, such that given three input files, apache.old, mysql.old and postgres.old, the script should trans6 years ago Read more
-
Blog postMy main Shell Scripting tutorial has moved to its own domain, at http://www.shellscript.sh/
This is easier to navigate, more tablet and mobile friendly, and generally more usable than before.
It also includes all the links to allow you to buy the content for yourself from Amazon (in eBook and Paperback), as well as for my full “Shell Scripting” book, as published by Wiley of New York.
And of course every page ends with a form to contact me with your feedback and com6 years ago Read more -
Blog post9 May 2016 Formatting and Displaying Time in Hours, Minutes and Seconds Sometimes a script will take a varying amount of time to run, and you want it to report how long it took. Sure, you can say when it started and finished, but that's not particularly helpful. The GNU Date command has the "date +%s" option, which gives you the number of seconds since 1st January, 196 years ago Read more
-
Blog post7 May 2016 Brian Kernighan, one of the co-creators of Unix, on the Unix Pipeline The Pipeline is one of the defining features of the Unix shell, and obviously, the same goes for Linux, MacOSX, and any other Unix-based or inspired systems. In a nutshell, it allows you to tie the output of one program to the input of another. That may not seem such a radical idea, but the6 years ago Read more
-
Blog post30 April 2016 Software Development Models Via https://toggl.com/images/landing-pages/software-development-methods-exp lained-with-cars-toggl-infographic-02.jpg [software-development-methods-explained-with-cars-toggl-infographic-02. jpg]6 years ago Read more
-
Blog post23 April 2016 The O'Reilly Animals: An Adult Coloring Book There are lots of amusing fake O'Reilly book covers going around the internet; however, this is a genuine 26-page O'Reilly book, in the vein of the "Adult Coloring Books" which are popular at the moment. So now you can colour in your Toucans, Fanfoot Geckos, Birdwings, Ring-Tailed Lemurs, and more, whe6 years ago Read more
-
Blog post16 April 2016 rm -rf / Okay, this story has been doing the rounds over the past few days, and I think it's time to talk about it: sudo rm -rf /* - source unknown [1]Man accidentally 'deletes his entire company' with one line of bad code. The gist of the story is that he had a script which did something along the lines of: #!/bin/sh f6 years ago Read more
-
Blog post4 April 2016 Where There Is A Shell, There Is A Way Where There Is A Shell, There Is A Way. [shell.jpg]6 years ago Read more
-
Blog postCreating an RPM package is incredibly easy, but somehow seems to be quite tricky to describe to people. I’ve written a short eBook (also available in Paperback) which comes with a free downloadable VirtualBox virtual machine image for working through the examples.
How to Create an RPM
I would love your feedback on this book, as it’s not a subject where there is necessarily a single “right” or “wrong” approach. What I’ve tried to cover here, is a minimal-effort guide to cr6 years ago Read more -
Blog post8 Dec 2015 Christmas! Using GNU Date to work out how many days until a given event (such as Christmas - 25th December) GNU's date tool offers a few additional features over the standard abilities of the traditional UNIX date facility. One of these is the "+%j" switch, which tells you the day's number as a day-of-the-year. So the first of January6 years ago Read more
-
Blog post13 Nov 2015 Shifting through Parameters Using the shift command to work through command-line arguments Is it 'parameters' or 'arguments'? Those words that you add to a command: "ls -l foo bar". For the purposes of this article, I'll use them both equally. Technically, "-l" is a switch, and foo and bar are arguments. Or possibly parameters. Anyway, this p7 years ago Read more
-
Blog post30 Oct 2015 Checking the exit status of ANY command in a pipeline It's a pretty common thing in a shell script to want to check the exit status of the previous command. You can do this with the $? variable, as is widely known: #!/bin/bash grep some.machine.example.com /etc/hosts if [ "$?" -ne "0" ]; then # The grep command failed to find "some.machine.example.com" in /7 years ago Read more
-
Blog post30 Oct 2015 Progress Bar Creating a simple Progress Bar for a shell script Sometimes all we need is a little patience. Or, at least, something to watch while we're waiting. The infamous Progress Bar is an example of such a thing. If your script needs to wait a while, particularly if it needs to wait for a fixed amount of time, this little progres7 years ago Read more
-
Blog post13 Oct 2015 The Story of Mel This was posted to USENET by its author, Ed Nather (nather@astro.as.utexas.edu), on May 21, 1983. This transcript, and notes, are taken from [1]http://www.catb.org/jargon/html/story-of-mel.html. A recent article devoted to the macho side of programming made the bald and unvarnished statement: Real Programmers7 years ago Read more
-
Blog postHere is a “minimal” guide to creating RPMs at http://steve-parker.org/rpm/ – I do plan to expand it further, but want to put something out there for now, for feedback at least, and to help people to make RPMs without necessarily having to dig deep into all the extra stuff that RPM can do for them.
I plan to make this into a more detailed and complete document, but for now, I’d love you to read this and tell me what you think.
7 years ago Read more -
Blog post4 Aug 2015 chmod 777 [chmod777.jpg] Why Not chmod 777? Because. But seriously, what are you trying to achieve? It is probably due to a misunderstanding of the Unix/Linux filesystem permissions model. The question is common (hence this page), but the answer is always the same: If you assess what your require7 years ago Read more
-
Blog post19 Jul 2015 What I Do / What I Think I Do [LinuxAdmin-steve-parker.org.jpg]7 years ago Read more
-
Blog post2 Jul 2015 Fork Bomb! Using shell builtin commands to deal with a fork-bombed machine A few days ago I had to deal with my first ever real-life fork-bombed server. By logging in to the console, I was somehow able to get a shell (one process). Having got that shell, even though I was root, it was difficult to be able to spawn other processes.7 years ago Read more
-
Blog post3 Jun 2015 Sorting on Fields The "sort" utility seems a pretty obvious thing. But it can catch you out in odd little ways. Here's a simple example. Given some machine sizings as follows, how does a script display and sort them appropriately?: Size CPU Memory Tiny 1 2048 Small 1 4096 Medium 2 4096 Big 2 8192 Large 47 years ago Read more
-
Blog post29 May 2015 Simple Shell Functions One of the steps along the journey from writing the occasional shell script to being a proficient shell scripter, is the creation of custom functions to create your own toolset. Here is a small but useful example of such a thing. If you want to run a set of tests (on how a system has been configured, or how well a7 years ago Read more
-
Blog post20 May 2015 Expanding Lists in Bash A useful but underused feature of the Bash shell is called Brace Expansion. It takes a few different forms, but basically, anything within the { braces } is expanded, either as a list: {apples,oranges,bananas}, a numerical sequence: {1..10}, or as characters: {a..z}. TL;DR. You can stop reading7 years ago Read more
-
Blog post20 May 2015 Generating Sequences in Bash A useful but underused feature of the Bash shell is called Brace Expansion. It takes a few different forms, but basically, anything within the { braces } is expanded, either as a list ({apples,oranges,bananas}), a numerical sequence ({1..10}), or characters ({a..z}). TL;DR. You can stop reading here and7 years ago Read more
-
Blog post15 May 2015 Nifty use of grep in a loop Grep is a widely known and used tool, but here is a use that you may not have considered before. GNU's grep, as used in Linux systems, and also available on some Unix systems (it may be installed as ggrep), has some additional features, one of which is --color, which can be used to highlight the matching sect7 years ago Read more
-
Blog post14 May 2015 RPM Package Versions A nice technique to split out an RPM package version, such as "1.12.14" into an array. Adapted from a Red Hat Satellite katello-ca-consumer package. This makes it easier to query the version, since "1.12.14" is not a real number and doesn't lend itself to comparison tests. $ PACKAGE=subscription-manager $ rpm -q --quer7 years ago Read more
-
Blog post14 May 2015 Trap die tip A useful technique in shell scripting is the set -e (or sh -e) option. This causes the script to exit on any error. However, the downside to this is that you don't get the chance to display any kind of error message, particularly if the failing command doesn't cause any output of its own in an error situation. Using7 years ago Read more
Titles By Steve Parker
Learn Linux / Unix shell scripting by example along with the theory.
What Makes This Book Special?
The content as well as the structure is designed to provide a strong competence with Shell Scripting, in an easy to follow way. Readers' feedback confirms that this is a successful format, and useful to people of all backgrounds.
This is a thorough yet practical tutorial with examples throughout. It has been written with extensive feedback from literally thousands of readers. These include new students as well as academics and seasoned professionals in the field. Some have a long Unix and/or Linux background, others have none.
This tutorial is currently cited by at least seven different University Degree courses around the world, as a teaching resource for their Undergraduates.
Table of Contents
- 1. Introduction
- 2. Philosophy
- 3. A First Script
- 4. Variables (Part 1)
- 5. Wildcards
- 6. Escape Characters
- 7. Loops
- 8. Test
- 9. Case
- 10. Variables (Part 2)
- 11. Variables (Part 3)
- 12. External Programs
- 13. Functions
- 14. Hints and Tips
- 15. Quick Reference
- 16. Interactive Shell
- 17. Exercises
The shell is the primary way of communicating with the Unix and Linux systems, providing a direct way to program by automating simple-to-intermediate tasks. With this book, Linux expert Steve Parker shares a collection of shell scripting recipes that can be used as is or easily modified for a variety of environments or situations. The book covers shell programming, with a focus on Linux and the Bash shell; it provides credible, real-world relevance, as well as providing the flexible tools to get started immediately.
- Shares a collection of helpful shell scripting recipes that can immediately be used for various of real-world challenges
- Features recipes for system tools, shell features, and systems administration
- Provides a host of plug and play recipes for to immediately apply and easily modify so the wheel doesn't have to be reinvented with each challenge faced
Come out of your shell and dive into this collection of tried and tested shell scripting recipes that you can start using right away!
The author is an independent IT consultant with almost two decades experience with Linux and RPM.