136 private links
The fundamental problem of shells is they are required to be two things.
A high-frequency REPL, which requires terseness, short command names, little to no syntax, implicit rather than explicit, so as to minimize the duration of REPL cycles.
A programming language, which requires readable and maintainable syntax, static types, modules, visibility, declarations, explicit configuration rather than implicit conventions.
And you can’t do both. You can’t be explicit and implicit, you can’t be terse and readable, you can’t be flexible and robust.
Shells optimize the former case, so that you can write cat beef.txt | grep "lasagna" | sort -n | uniq instead of:
with open(Path("beef.txt")) as stream:
lines = filter(
stream.readlines(),
lambda line: re.match(line, "lasagna") is not None
)
print(set(reverse(sorted(lines))))
Which does not spark joy.
So the programming language aspect suffers: shell scripts are an unreadable nightmare of stringly-typed code resembling cyphertext.
Shell is a thing you want to understand and then not use, because you learned to understand it. (in German, from 1998 )
For the rest of this discussion, we assume “Python 3” as an instance of “something else”, but if you are older than 50, feel free to use “Perl” instead.
If you are already doing Python, the rest of this is not for you. You already know these things.
A gentle admonishment to use shell scripts where appropriate accept that shell scripts will appear in your codebases and to lean heavily on automated tools, modern features, safety rails, and best practices whenever possible.
This article will teach you how to create and use these five types of aliases:
Simple Aliases
Suffix Aliases
Functions for Aliases With Parameters
Global Aliases
Operating system specific aliases
One of the things that makes the shell an invaluable tool is the amount of available text processing commands, and the ability to easily pipe them into each other to build complex text processing workflows. These commands can make it trivial to perform text and data analysis, convert data between different formats, filter lines, etc.
When working with text data, the philosophy is to break any complex problem you have into a set of smaller ones, and to solve each of them with a specialized tool.
Shell Files and Interpreter Invocation
Environment
Comments
Formatting
Features and Bugs
Naming Conventions
Calling Commands
Conclusion
Fail fast, fail noisy.
Parameter expansion is the procedure to get the value from the referenced entity, like expanding a variable to print its value. On expansion time you can do very nasty things with the parameter or its value. These things are described here.
#Planet #Commandline is finally online: http://planet-commandline.org/ #cli #ssh #shell #grml #gnuscreen #zsh
Terminator is a cross-platform GPL terminal emulator with advanced features not yet found elsewhere.