Entries tagged as advent calendar

ZSH Gem #8: Hook function chpwd()

Posted by | Comment (1) | Trackbacks (2)

There is a number of magic functions called hook functions in ZSH which are automatically executed under certain circumstances. One of these functions is chpwd() and it is executed each time you change the current working directory.

Read more…

ZSH Gem #7: Editing variables with vared

Posted by | Comments (2) | Trackbacks (0)
Today I'm showing you how to edit variables by using vared. The vared shell builtin invokes the ZSH line editor, to interactively edit variables. This is sometimes very useful when you have appended values to a variable but then recognize that you added something you didn't want to add. Instead of rebuilding all the contents of the variable you could just use vared and clean up the mess.

Read more…

ZSH Gem #6: Redirect output to multiple files

Posted by | Comments (4) | Trackbacks (0)

One unique feature in ZSH is that you can redirect streams to multiple outputs or inputs simultaneously. With this multi-stream redirection you can, e.g., redirect STDOUT OR STDERR of a program to more than one file at the same time without using a command line tool such as tee.

Read more…

ZSH Gem #5: Menu selection

Posted by | Comments (3) | Trackbacks (0)

By default, the ZSH auto completion is very rough. This seems very weird when you think of how powerful ZSH's expansion system is where you can expand any expression with the TAB key. But when you hit TAB to complete something, the only thing you can do is to toggle through a very basic list of files or commands.

But in fact, the ZSH completion system is very powerful. And when I say that, I mean very powerful. ZSH has a completely programmable completion system. For a long time, this has been a killer feature of ZSH. It still is, but other shells such as Bash have now implemented this as well. But in some areas, the ZSH completion system might still be the better one.

Read more…

ZSH Gem #4: Spell checking and auto correction

Posted by | Comments (0) | Trackback (1)

It often happens that you type a command, hit enter and then notice that you spelled the command incorrectly and your shell tells you something like:

zsh: command not found: wrongcommand

That is not a big problem, but especially when your command is very long, it is sometimes tedious to jump to the first word and correct it. You might configure your HOME key to do that, but sometimes this is not possible. It would be very convenient if the shell would not just say that you misspelled the command but also give you some alternative you'd only have to confirm with a keystroke. Well, ZSH can do that.

Read more…

ZSH Gem #3: No automatic word split

Posted by | Comments (2) | Trackbacks (0)

Have you ever stumbled upon this: you write a shell script which works with variables containing spaces and suddenly the whole script breaks? This is because most shells automatically split strings on spaces. This is some ancient behavior and in most cases it is just a pain in the ass.

Read more…

ZSH Gem #2: Extended globbing and expansion

Posted by | Comments (9) | Trackbacks (0)

You are probably familiar with globbing. Globbing is a way to select files on the command line based on a simple pattern. Newer versions of Bash can do a lot more, but I'll show you what the Z Shell can do.

Read more…

ZSH Gem #1: Programmable file renaming

Posted by | Comments (8) | Trackbacks (0)

Welcome to the first article of this year's Advent calendar series. The last Advent calendar was extremely successful so I thought it would be a good idea to continue this.

The topic for the Advent calendar series 2011 is “24 Outstanding ZSH Gems” because the Z Shell is my absolute favorite shell. There's nothing ZSH can't do except the dishes. In my opinion it's much more powerful than any other shell out there. If you are not a ZSH user (yet?), you're still very welcome to enjoy this series as well. Maybe then you'll make the switch. And if not: some features also work similarly in Bash, although they might be not so comfortable there. wink

Now let's begin with programmable renaming of files or batch renaming. That sounds very abstract, but let me show you what I mean.

Read more…

#24: The awk basics

Posted by | Comments (2) | Trackbacks (2)

awk is very complex and hard to learn. It is the most difficult task in Linux administrator's lives and drives everyone crazy who tries to learn it. It's written by Gods and used by them, no mortal man can ever learn awk.

In fact…, no! If you know any C-like programming language and regular expressions, awk is absolutely easy and it can make things much easier. It's pretty mighty, but I've never seen any programming language easier than awk (except QBasic).

Read more…

#23: File descriptors

Posted by | Comments (0) | Trackbacks (3)

File descriptors are very essential in programming. When you open a file, you get a token, which identifies the file instance. With this token you refer to the file, write, read or close it. You have about the same on the shell.

Read more…

#22: Processes with high and low priority

Posted by | Comments (4) | Trackbacks (3)

Processes in Linux may run with different priorities so that important processes get more CPU time than less important ones. This priority is called the “nice value” or ”niceness” (NI). The nice value is a number between -20 and +19 with the default value right in the center at 0. The higher this nice value, the “nicer” a process is to others, i.e., the lower its priority.

Read more…

#21: The command line calculator bc

Posted by | Comments (2) | Trackbacks (2)

Performing calculations on the command line is very handy and bc is the tool which does it for you. Also bash can do some calculation stuff, but that's not very intuitive. Bash is built for different things than calculation and so bc is the better choice. It can do much more for you and its syntax is ways easier.

Read more…

#20: Multi-line sed search and replace

Posted by | Comments (11) | Trackbacks (3)

sed is built to process strings (either from STDIN or from a file) line by line. Therefore, you can't search for multiple lines. But there are several ways to work around this. I'll be showing you three ways of performing multi-line replacements.

Read more…

#19: Label partitions

Posted by | Comments (0) | Trackbacks (2)

On Linux devices and their partitions are named automatically when being plugged in. They have a base name (for SCSI devices it's sd), a device identifier (a lowercase letter) and a number for every partition. These names depend on the order in which the devices are plugged in, so they are not static at all.

Read more…

#18: GNU find operators

Posted by | Comments (0) | Trackbacks (2)

This is not a tutorial about find in general as you might expect it. find, and the GNU variant in particular, is very complex and can't be covered in one short blog post and actually, there are many good tutorials on the Internet. Instead, this blog post concentrates on one single aspect of find: operators.

Read more…

   (Page 2 of 4, totaling 47 entries)
Design and Code Copyright © 2010-2019 Janek Bevendorff Content on this site is published under the terms of the GNU Free Documentation License (GFDL). You may redistribute content only in compliance with these terms. tweetbackcheck