Linux Fu: Gum Up Your Script

We often write quick bash scripts and judging by the comments, half of us use bash or a similar shell to pop out quick, useful scripts, and half of us think that’s an abomination, and you should only use bash for your command line and resort to something more like a traditional language to do anything else. If you’re in the former camp, you’re probably cursing your allegiance when you need to make your bash scripts more interactive.

Gum can help. It’s a utility that can handle your script input and output with a little flair while requiring almost no effort on your part.

The command looks simple, but it has twelve subcommands, each with myriad options. But you can break down the functions into a few simple categories. The input commands let you prompt for a line of input or a bunch of lines of input. You can also create a pick list or a yes/no type of prompt. There’s also a file picker and a filter, sort of like fzf.

Continue reading “Linux Fu: Gum Up Your Script”

Linux Fu: Sharing Your Single WiFi

If you are trying to build a router or access point, you’ll need to dig into some of the details of networking that are normally hidden from you. But, for a normal WiFi connection, things mostly just work, even though that hasn’t always been the case. However, I ran into a special case the other day where I needed a little custom networking, and then I found a great answer to automate the whole process. It all comes down to hotel WiFi. How can you make your Linux laptop connect to a public WiFi spot and then rebroadcast it as a private WiFI network? In particular, I wanted to connect an older Chromecast to the network.

Hotel WiFi used to be expensive, but now, generally, it is free. There was a time when I carried a dedicated little box that could take a wired or wireless network and broadcast its own WiFi signal. These were actually fairly common, but you had to be careful as some would only broadcast a wired network connection. It was more difficult to make the wireless network share as a new wireless network, but some little travel routers could do it. Alternatively, you could install one of the open router firmware systems and set it up. But lately, I haven’t been carrying anything like that. With free WiFi, you can just connect your different devices directly to the network. But then there’s the Chromecast and the dreaded hotel login.

Continue reading “Linux Fu: Sharing Your Single WiFi”

Linux Fu: The Shell Forth Programmers Will Love

One of the most powerful features of Unix and Linux is that using traditional command line tools, everything is a stream of bytes. Granted, modern software has blurred this a bit, but at the command line, everything is text with certain loose conventions about what separates fields and records. This lets you do things like take a directory listing, sort it, remove the duplicates, and compare it to another directory listing. But what if the shell understood more data types other than streams? You might argue it would make some things better and some things worse, but you don’t have to guess, you can install cosh, a shell that provides tools to produce and work with structured data types.

The system is written with Rust, so you will need Rust setup to compile it. For most distributions, that’s just a package install (rust-all in Ubuntu-like distros, for example). Once you have it running, you’ll have a few new things to learn compared to other shells you’ve used. Continue reading “Linux Fu: The Shell Forth Programmers Will Love”

Linux Fu: UEFI Booting

Unless your computer is pretty old, it probably uses UEFI (Unified Extensible Firmware Interface) to boot. The idea is that a bootloader picks up files from an EFI partition and uses them to start your operating system. If you use Windows, you get Windows. If you use Linux, there’s a good chance you’ll use Grub which may or may not show you a menu. The problem with Grub is you have to do a lot of configuration to get it to do different things. Granted, distros like Ubuntu have tools that go through and do much of the work for you and if you are satisfied with that, there’s no harm in using Grub to boot and manage multiple operating systems.

An alternative would be rEFInd, which is a nice modern UEFI boot manager. If you are still booting through normal (legacy) BIOS, the installation might be a hassle. But, in general, rEFInd, once installed, just automatically picks up most things, including Windows, Mac, and Linux operating systems and kernels. The biggest reasons you might change the configuration is if you want to hide some things you don’t care about or change the visual theme.

Continue reading “Linux Fu: UEFI Booting”

Linux Fu: Miller The Killer Makes CSV No Pest

Historically, one of the nice things about Unix and Linux is that everything is a file, and files are just sequences of characters. Of course, modern practice is that everything is not a file, and there is a proliferation of files with some imposed structure. However, if you’ve ever worked on old systems where your file access was by the block, you’ll appreciate the Unix-like files. Classic tools like awk, sed, and grep work with this idea. Files are just characters. But this sometimes has its problems. That’s the motivation behind a tool called Miller, and I think it deserves more attention because, for certain tasks, it is a lifesaver.

The Problem

Consider trying to process a comma-delimited file, known as a CSV file. There are a lot of variations to this type of file. Here’s one that defines two “columns.” I’ve deliberately used different line formats as a test, but most often, you get one format for the entire file:

Slot,String 
A,"Hello" 
"B",Howdy 
"C","Hello Hackaday" 
"D","""Madam, I'm Adam,"" he said." 
E 100,With some spaces!
X,"With a comma, or two, even"

Continue reading “Linux Fu: Miller The Killer Makes CSV No Pest”

Linux Fu: Easy VMs

It wasn’t long ago that we looked at easily creating Docker containers from the command line so you could just easily spin up a virtual environment for development. Wouldn’t it be nice if you could do the same for virtual machines? You can. Using Multipass from Canonical, the makers of Ubuntu, you can easily spin up virtual machines under Linux, Mac, or Windows. Granted, most of the virtual machines in question are variations of Ubuntu, but there are some additional images available, and you can create your own.

Once you have it installed, starting up a new Ubuntu instance is trivial. If you have a set configuration, you can even set up predefined setups using a YAML file.

Continue reading “Linux Fu: Easy VMs”

Linux Fu: Atomic Power

People are well aware of the power of virtual machines. If you want to do something dangerous — say, hack on the kernel — you can create a virtual machine, snapshot it, screw it up a few times, restore it, and your main computer never misses a beat. But sometimes you need just a little shift in perspective, not an entire make belive computer. For example, you are building a new boot disk and you want to pretend it is the real boot disk and make some updates. For that there is chroot, a Linux command that lets you temporarily open processes that think the root of the filesystem is in a different place than the real root. The problem is, it is hard to manage a bunch of chroot environments which is why they created Atoms.

The system works with several common distributions and you install it via Flatpak. That means you can launch, for example, a shell that thinks it is running Gentoo or Centos Linux under Ubuntu.

Continue reading “Linux Fu: Atomic Power”