![]() Could that have been done in fewer steps? Absolutely.You may be asking some of the same questions I did when I started digging into this particular example. Zulu18.32.13-ca-jdk18.0.2.1-macosx_aarch64.dmg A little brain salad surgery Zulu18.32.13-ca-jdk18.0.2.1-macosx_aarch64.dmg tail -1įinally, “tail”, which returns only the last part of any input you give it, “-1” indicating it should only return one line, the last line. ![]() In this case, sorting on the release date or the version numbers gives the same result, and the lines remain in the same order as before.Īnother cut, this time from the character at position 11 onward, which removes the ten digits of the YYYY-MM-DD formatted modification date. ![]() in ascending order, small numbers first, then A to Z. It sorts the lines of input alphabetically, or (from the “sort” documentation) “lexicographically, according to the current locale's collating rules”. You’ll notice the output has also stripped out the whitespace. The third word, the file’s modification time, is omitted. ![]() ($0 is the entire string.)Īll this “awk” command is doing is printing the second word of each line, then the first. So, the first word is “$1”, the second “$2” and so on. Each “field” is treated as a variable, and they are addressed by their numerical position in the text. Without any other operators, “awk” will try to break up a line into words or “fields”, based on a default set of whitespace “separator” characters – space, tab, and a few other non-printing ASCII control characters. Like “sed”, “awk” operates on a line of text at a time, and in this case the command is the self-explanatory “print”. Again, the command is enclosed in single quotes, and “awk” operations are set off with braces. Like “sed” before, “awk” ( “AWK! AWK! CAW!” ) has its own command language and syntax. Which brings us to “awk” which I read inside my head (and sometimes aloud) as the sound of an angry crow. This is part of a function for determining the latest version of the Zulu open source Java runtime tools:Ĭurl -fs "" | grep -Eio '">zulu18.*ca-jdk18.*aarch64.dmg(.*)' | cut -c 3- | sed 's///' | sed -E 's/(*)M//' | awk '' Take, for instance, this monstrosity I found whilst spelunking the source for Installomator ( ). Properly crafted, a one-liner simultaneously saves space and unfortunately renders the operations therein utterly opaque to the inexperienced eye: a kind of gatekeeping for command line jockey wannabes. Like Michelangelo, chipping away all of the marble that isn’t “David”. Shuttling a block of data through a complex pipeline of edits and transforms to extract just the functionally relevant bits is a kind of art. Papa’s got a brand new bagĪs I’ve mentioned before, I believe there’s a certain utilitarian beauty in constructing one-line shell commands. Rather than discarding what you already know in favor of an unfamiliar language, consider adding “pwsh” to your existing vocabulary. No, most Mac admins who have command line experience are pretty happy with bash, and (maybe reluctantly) getting accustomed to the newfangled zsh all the kids are raving about. Unless you’re only reading for the bad jokes and puns, in which case be sure to comment, like, and subscribe. I expect, though, if you’re reading this series, you’re not already a regular PowerShell user. Sure, if you’re a Windows expat who yearns for some familiar vestige of your former OS, go for it. While it’s possible to set your default login shell to pwsh (chsh -s /usr/local/bin/pwsh) I wouldn’t necessarily go that far. One thing we haven’t explored yet is integrating PowerShell into your everyday workflows. But it’s not your “every day carry”, in the parlance of pocket knife and multitool enthusiasts. Maybe you’ll keep PowerShell (and the sample scripts we’ve built) in mind if you’re ever tasked with building reports or sifting through reams of structured data. If you’re still on the fence, you can agree PowerShell has certain advantages in some areas over other scripting languages. At this point in the series, I would hope you need no further convincing of PowerShell’s utility, even to someone whose main job is maintaining and managing Macs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |